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

后端 未结 6 655
星月不相逢
星月不相逢 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:13

    FWIW, here's a templated function in the same vein as eudoxos' solution:

    namespace py = boost::python;
    
    template
    py::list std_vector_to_py_list(const std::vector& v)
    {
      py::list l;
      typename std::vector::const_iterator it;
      for (it = v.begin(); it != v.end(); ++it)
        l.append(*it);   
      return l;  
    }
    

提交回复
热议问题