pybind11/tests/test_stl_binders.cpp

48 lines
1.3 KiB
C++
Raw Normal View History

2016-05-07 04:26:19 +00:00
/*
tests/test_stl_binders.cpp -- Usage of stl_binders functions
2016-05-07 04:26:19 +00:00
2016-05-15 18:50:38 +00:00
Copyright (c) 2016 Sergey Lyskov
2016-05-07 04:26:19 +00:00
All rights reserved. Use of this source code is governed by a
BSD-style license that can be found in the LICENSE file.
*/
#include "pybind11_tests.h"
2016-05-07 04:26:19 +00:00
2016-05-15 18:50:38 +00:00
#include <pybind11/stl_bind.h>
2016-09-06 04:02:29 +00:00
#include <map>
#include <unordered_map>
2016-05-07 04:26:19 +00:00
2016-05-15 18:50:38 +00:00
class El {
2016-05-07 04:26:19 +00:00
public:
El() = delete;
El(int v) : a(v) { }
int a;
2016-05-07 04:26:19 +00:00
};
2016-05-15 18:50:38 +00:00
std::ostream & operator<<(std::ostream &s, El const&v) {
s << "El{" << v.a << '}';
return s;
}
test_initializer stl_binder_vector([](py::module &m) {
py::class_<El>(m, "El")
.def(py::init<int>());
2016-09-06 04:02:29 +00:00
py::bind_vector<std::vector<unsigned int>>(m, "VectorInt");
py::bind_vector<std::vector<bool>>(m, "VectorBool");
2016-05-15 18:50:38 +00:00
2016-09-06 04:02:29 +00:00
py::bind_vector<std::vector<El>>(m, "VectorEl");
2016-05-07 04:26:19 +00:00
2016-09-06 04:02:29 +00:00
py::bind_vector<std::vector<std::vector<El>>>(m, "VectorVectorEl");
2016-08-30 02:50:38 +00:00
});
test_initializer stl_binder_map([](py::module &m) {
2016-09-06 04:02:29 +00:00
py::bind_map<std::map<std::string, double>>(m, "MapStringDouble");
py::bind_map<std::unordered_map<std::string, double>>(m, "UnorderedMapStringDouble");
2016-08-30 02:50:38 +00:00
2016-09-06 04:02:29 +00:00
py::bind_map<std::map<std::string, double const>>(m, "MapStringDoubleConst");
py::bind_map<std::unordered_map<std::string, double const>>(m, "UnorderedMapStringDoubleConst");
});