[C++-sig] Wrapping std::vector<int> with boost::python::list

fjanoos fjanoos at yahoo.com
Tue Aug 9 23:21:37 CEST 2011


I'm new to boost::python and was having trouble wrapping a C++ function of
the form
 void FindVCs(int vId, vector<int>& vcs);

Here vcs is allocated in the caller and populated by FindVCs.

Initially, I considered wrapping it something like this:

        boost::python::list* FindVCs_wrap(int vid)
                vector<int> vcs;
                //wrap and return
                boost::python::list* out_list = new boost::python::list;
                unsigned int num_elems = vcs.size();
                for( unsigned int idx = 0; idx < num_elems; idx++){
                return out_list;

however, this gives me compile time errors
Error 5 error C2027: use of undefined type

Then I change the return type to

boost::shared_ptr<boost::python::list> FindVCs_wrap(int vid)
        return boost::shared_ptr<boost::python::list>(out_list);

This compiles fine but then at runtime Python raises:

TypeError: No to_python (by-value) converter found for C++ type: class
boost::shared_ptr<class boost

Any ideas of what I am doing wrong ? 


View this message in context: http://boost.2283326.n4.nabble.com/Wrapping-std-vector-int-with-boost-python-list-tp3731291p3731291.html
Sent from the Python - c++-sig mailing list archive at Nabble.com.

More information about the Cplusplus-sig mailing list