Boost logo

Boost :

Subject: Re: [boost] [variant] address of a variant type from the addressofitssub-object?
From: Larry Evans (cppljevans_at_[hidden])
Date: 2016-04-15 06:26:47


On 04/15/2016 03:10 AM, Andrzej Krzemienski wrote:
[snip]

> Thank you for putting it this way. Ultimately my goal is to compare two
> ways of representing a (mathematical) expression tree. I tried one with
> OO-based virtual dispatch:
>
> ```
> struct AdditioNode : NodeInterface
> {
> unique_ptr<NodeInterface> leftSubexpression, rightSubexpression;
> double eval() override;
> };
> // etc...
> ```
>
> And storing variants in a vector and representing links to subnodes as
> indexes:
>
> ```
> struct Addition
> {
> int leftSubexpression, rightSubexpression;
> };
>
> using Node = variant<Addition, ...>;
> using ExpressionTree = vector<Node>;
> ```
>
> I haven't done any profiling yet, but my benchmarks show, the former one
> (with virtual interfaces) is about twice faster. I found it quite
> surprising.
>

Other people got similar surprising performance results:

http://stackoverflow.com/questions/11906741/boost-variant-vs-virtual-interface-performance

-regards,
Larry


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk