|
Boost : |
Subject: Re: [boost] [variant] address of a variant type from the address of itssub-object?
From: Andrzej Krzemienski (akrzemi1_at_[hidden])
Date: 2016-04-14 07:27:37
2016-04-14 13:06 GMT+02:00 Peter Dimov <lists_at_[hidden]>:
> Andrzej Krzemienski wrote:
>
>> The problem I am solving is to how to access the whole variant object
>> from inside a static visitor:
>>
>> ```
>> using VariantOb = boost::variant<Ob>;
>>
>> struct MyVisitor : boost::static_visitor<>
>> {
>> void operator()(Ob const& ob) const
>>
>
> Can't you have
>
> struct MyVisitor
> {
> typedef void result_type;
> void operator()(Ob const& ob, Var const& var) const;
> };
>
> and then pass bind( MyVisitor(), _1, ref(v) ) to visit?
>
I suppose, I can. In fact, currently my visitor looks like this:
```
struct MyVisitor : boost::static_visitor<>
{
VariantOb const& v_;
MyVisitor(VariantOb const& v) : v_(v) {}
void operator()(Ob const& ob) const
{
boost::addressof(v_);
}
};
```
But, I am trying to optimize a function that I believe is slower than
ideal, and my hypothesis is that this carrying of the additional pointer
around is the culprit. In order to confirm it, I need to be able to get the
address of the containing variant object in flight and compare this to the
current solution.
Regards,
&rzej
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk