Welcome to mirror list, hosted at ThFree Co, Russian Federation.

vector_list_conversion.hpp « pyhelpers - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 52ef1f108015ae8ddd50ab5457ba341941dadcb1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#pragma once

#include <vector>

#include <boost/python.hpp>
#include <boost/python/stl_iterator.hpp>

namespace
{
template <typename T>
std::vector<T> python_list_to_std_vector(boost::python::object const & iterable)
{
  return std::vector<T>(boost::python::stl_input_iterator<T>(iterable),
                        boost::python::stl_input_iterator<T>());
}

// For this to work one should define
// class_<std::vector<YourClass>>("YourClassList")
//   .def(vector_indexing_suite<std::vector<YourClass>>());
template <typename T>
boost::python::list std_vector_to_python_list(std::vector<T> const & v)
{
  boost::python::object get_iter = boost::python::iterator<std::vector<T>>();
  return boost::python::list(get_iter(v));
}
}  // namespace