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

Stefan Ring stefanrin at gmail.com
Sat Aug 15 14:16:18 CEST 2015


On Mon, Aug 10, 2015 at 5:00 PM, Mario Lang <mlang at delysid.org> wrote:
> 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.

Interesting question and interesting blog post! Unfortunately, I don't
have an answer. I'm not familiar enough with Boost.Variant, and I have
not had to dig through Boost.Python reference documentation for quite
a while. I have no idea what is the intended level of interoperability
with Boost.Variant.


More information about the Cplusplus-sig mailing list