Thanks Jim, adding the extra parentheses solved the problem. I'll contact the Boost.Variant people.
- bryan On Tue, May 7, 2013 at 4:28 PM, Jim Bosch <tallji...@gmail.com> wrote: > On 05/07/2013 07:19 PM, Bryan Catanzaro wrote: > >> Hi - >> Using Boost 1.53.0, the following code fails to compile with g++, when >> c++11 is enabled: >> >> #include <boost/python.hpp> >> #include <boost/variant.hpp> >> >> struct A{}; struct B{}; >> >> typedef boost::variant<A, B> my_variant; >> >> void foo(boost::python::object o) { >> my_variant v = boost::python::extract<my_**variant>(o); >> } >> >> The error is: >> /home/bcatanzaro/boost_1_53_0/**boost/variant/variant.hpp:**1574:9: >> error: no matching function for call to ‘boost::variant<A, >> B>::initializer::initialize(**void*, std::remove_reference<boost::** >> python::extract<boost::**variant<A, B> >&>::type)’ >> >> Looking at the relevant line in boost/variant/variant.hpp, it looks like >> variant is attempting to convert the boost::python::extract<my_**variant> >> object into either A or B, and failing to find a conversion. Since this >> code compiles when c++11 is not enabled, it appears rvalue references >> coupled with boost::python::extract are confusing boost::variant's >> constructor selection; I would expect it should be copy constructing from >> variant<A, B>, rather than convert constructing into A or B. >> >> Any advice or workarounds? Turning off c++11 is difficult, since the >> whole project relies on it. The code compiles correctly with c++11 turned >> on with Boost 1.48.0, so it appears something has regressed. >> >> > Hmm...maybe try this? > > my_variant v = boost::python::extract<my_**variant>(o)(); > > (note the extra parenthesis). Or this: > > my_variant v = boost::python::extract<my_**variant const &>(o)(); > > I haven't checked, but I'd be very surprised if the change between 1.48 > and 1.53 was in Boost.Python, so that means you can probably reproduce it > without Boost.Python and maybe report it to the Boost.Variant people as a > regression there. > > > Jim > >
_______________________________________________ Cplusplus-sig mailing list Cplusplus-sig@python.org http://mail.python.org/mailman/listinfo/cplusplus-sig