You can find converters for Boost.Fusion in the python_extensions
package in the Boost sandbox; along with Fusion's adapters for
boost::tuple (see the Fusion docs), that should give you what you need:

https://svn.boost.org/svn/boost/sandbox/python_extensions/

> ...
>
Jim

Hi Jim,

I have tested your code. I used it to convert from Python sequence to std::vector and to boost::tuple. Everything works fine. Your code would be a valuable addition to the Boost.Python library.

A few comments:

1. Many application developers use boost::tuple or std::tuple but have never heard of Boost.Fusion. For their benefit you might add a header that handles boost::tuple and std::tuple while hiding the Boost.Fusion stuff.
Something like the following should suffice

    // boost/python/from_python/tuple.hpp

    #ifndef BOOST_PYTHON_FROM_PYTHON_TUPLE_HPP
    #define BOOST_PYTHON_FROM_PYTHON_TUPLE_HPP

    #include <boost/fusion/include/tuple.hpp>
    #include <boost/fusion/include/boost_tuple.hpp>
    #include <boost/python/from_python/boost_fusion.hpp>

    namespace boost { namespace python {

        template <typename Sequence>
        struct tuple_from_python
      : boost_fusion_from_python<Sequence> {};

    }}

    #endif


2. If you change boost/python/from_python/container.hpp line 46 from

     } catch (error_already_set & err) {

to

     } catch (error_already_set &) {

then you get rid of a compiler warning (on MSVS 2010).


3. I feel the naming of some of the headers and classes is a bit inconsistent. Why

    boost::python::tuple_from_python

and

    boost::python::container_from_python_sequence

Both convert from Python sequences.


4. I also tested with std::tuple (on MSVS 2010) and that did not work.
I got the error message

1>C:\Libraries\Boost\boost_1_48_0\boost/mpl/for_each.hpp(95): error C2664: 'boost::mpl::assertion_failed' : cannot convert parameter 1 from 'boost::mpl::failed ************boost::mpl::is_sequence<T>::* ***********' to 'boost::mpl::assert<false>::type'
1>          with
1>          [
1>              T=std::tr1::tuple<std::string,double,bool>
1>          ]
1> No constructor could take the source type, or constructor overload resolution was ambiguous

--Johan




_______________________________________________
Cplusplus-sig mailing list
Cplusplus-sig@python.org
http://mail.python.org/mailman/listinfo/cplusplus-sig

Reply via email to