VectorPyList.hpp
1 // Distributed under the MIT License.
2 // See LICENSE.txt for details.
3 
4 #pragma once
5 
6 #include <vector>
7 
8 #include <boost/python.hpp>
9 #include <boost/python/stl_iterator.hpp>
10 #include <boost/python/suite/indexing/vector_indexing_suite.hpp>
11 
12 namespace bp = boost::python;
13 
14 namespace py_bindings {
15 template <typename T>
16 std::vector<T> py_list_to_std_vector(const bp::object& iterable) {
17  return std::vector<T>(bp::stl_input_iterator<T>(iterable),
18  bp::stl_input_iterator<T>());
19 }
20 
21 template <class T>
22 bp::list std_vector_to_py_list(const std::vector<T>& vector) {
23  bp::list list;
24  for (auto iter = vector.begin(); iter != vector.end(); ++iter) {
25  list.append(*iter);
26  }
27  return list;
28 }
29 
30 } // namespace py_bindings
Definition: Bindings.cpp:25