std::vector to boost::python::list

后端 未结 6 656
星月不相逢
星月不相逢 2020-11-27 02:28

I have a method in c++ that gets called from python and needs to return a python list object.

I have already created the method, and its attached to an exposed class

6条回答
  •  一生所求
    2020-11-27 03:14

    I have this function using iterators to convert std::vector to py::list:

    namespace py = boost::python;
    
    template
    py::list std_vector_to_py_list(const std::vector& v)
    {
        py::object get_iter = py::iterator >();
        py::object iter = get_iter(v);
        py::list l(iter);
        return l;
    }
    

提交回复
热议问题