[C++-sig] [Boost.Python] Treating boost::variant like a reference?

Mario Lang mlang at delysid.org
Mon Aug 10 17:00:37 CEST 2015


Hi.

I am trying (off and on, because it would be useful, but I am not quite
there yet) to find a way to make Boost.Python cooperate with
Boost.Variant.  I sort of managed to make a variant behave like a
value.  However, things like modification of a variant inside of a
container doesn't work, because the variant is converted from/to python
everytime it is accessed.  Looking at the Boost.Python docs and code, I
think there should be a way to treat a variant like a proxy/reference.
The only problem is, that Boost.Python would *know* the C++ type of the
referenced object only at runtime.  While that shouldn't be a problem
for Python,
It looks like Boost.Python doesn't support this.  But maybe there is
some way to still acomplish that, and I have missed it?

boost.variant is common enough that it would be worthwhile to have
boost.python support it as best as possible.  It took me quite a while
to figure out what I have written below, so, in case there is no better
solution, maybe we want to add something about variants to the
boost.python docs to get people started a little easier?

I've written up what I have found so far here:
http://blind.guru/boost_python-and-boost_variant.html

Any input appreciated.

-- 
CYa,
  ⡍⠁⠗⠊⠕


More information about the Cplusplus-sig mailing list