Boost logo

Boost :

Subject: Re: [boost] [variant] address of a variant type from the addressofitssub-object?
From: Peter Dimov (lists_at_[hidden])
Date: 2016-04-14 11:47:28

Chris Glover wrote:
> > That's hard to believe. Copying a pointer should be insignificant
> > compared to the cost of the dispatch. What does the profiler say?
> Which compiler? I have found that MSVC is extremely pessimistic with this
> type of situation and generates unnecessary mov instructions for the
> pointer in the struct.

It's inside a switch on the type index. A mov instruction or two shouldn't
matter. The generated code should be something like

    switch( v.which() )
    case 0:

        my_visitor( get<T1>(v) );

    case 1:

        my_visitor( get<T2>(v) );

    // and so on

except with about seven layers of templates on top. I just don't see an
extra pointer copy being of significance here. If the switch is compiled to
a table you have an indirect jmp; if to a sequence of comparisons, would
depend on how well they can be predicted.

Boost list run by bdawes at, gregod at, cpdaniel at, john at