Boost logo

Boost :

Subject: [boost] [variant] address of a variant type from the address of its sub-object?
From: Andrzej Krzemienski (akrzemi1_at_[hidden])
Date: 2016-04-14 02:39:02

Is there a portable way (guaranteed by the interface) to do the following?

I have an object 'ob' of type Ob and know its address. I know it is an
active sub-object of a variant type, where Ob is one of the sub-types. Is
there a way to compute the address of the containing variant object?

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
    // --> get the address of the variant object ?
   boost::addressof(ob) + what_offset; ??


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