Created
November 5, 2015 04:19
-
-
Save marcinwol/b8df949bf8009cf856a3 to your computer and use it in GitHub Desktop.
Boost python vector to py list and py list to vector
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <vector> | |
#include <memory> | |
#include "boost/shared_ptr.hpp" | |
#include "boost/python.hpp" | |
#include "boost/python/stl_iterator.hpp" | |
using namespace std; | |
template<typename T> | |
inline | |
std::vector< T > py_list_to_std_vector( const boost::python::object& iterable ) | |
{ | |
return std::vector< T >( boost::python::stl_input_iterator< T >( iterable ), | |
boost::python::stl_input_iterator< T >( ) ); | |
} | |
template <class T> | |
inline | |
boost::python::list std_vector_to_py_list(std::vector<T> vector) { | |
typename std::vector<T>::iterator iter; | |
boost::python::list list; | |
for (iter = vector.begin(); iter != vector.end(); ++iter) { | |
list.append(*iter); | |
} | |
return list; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What next to do with list? How to past it to python? For classes we use syntax class_..