Sergey Lyskov | eae7744 | 2016-05-07 00:26:19 -0400 | [diff] [blame] | 1 | /* |
Sergey Lyskov | a95bde1 | 2016-05-08 19:31:55 -0400 | [diff] [blame] | 2 | example/example17.cpp -- Usage of stl_binders functions |
Sergey Lyskov | eae7744 | 2016-05-07 00:26:19 -0400 | [diff] [blame] | 3 | |
| 4 | Copyright (c) 2016 Wenzel Jakob <wenzel.jakob@epfl.ch> |
| 5 | |
| 6 | All rights reserved. Use of this source code is governed by a |
| 7 | BSD-style license that can be found in the LICENSE file. |
| 8 | */ |
| 9 | |
| 10 | #include "example.h" |
| 11 | |
| 12 | #include <pybind11/stl_binders.h> |
| 13 | |
Sergey Lyskov | a95bde1 | 2016-05-08 19:31:55 -0400 | [diff] [blame] | 14 | |
| 15 | class A { |
Sergey Lyskov | eae7744 | 2016-05-07 00:26:19 -0400 | [diff] [blame] | 16 | public: |
| 17 | A() = delete; |
Sergey Lyskov | a95bde1 | 2016-05-08 19:31:55 -0400 | [diff] [blame] | 18 | A(int v) :a(v) {} |
| 19 | |
| 20 | int a; |
Sergey Lyskov | eae7744 | 2016-05-07 00:26:19 -0400 | [diff] [blame] | 21 | }; |
| 22 | |
Sergey Lyskov | eae7744 | 2016-05-07 00:26:19 -0400 | [diff] [blame] | 23 | |
Sergey Lyskov | a95bde1 | 2016-05-08 19:31:55 -0400 | [diff] [blame] | 24 | std::ostream & operator<<(std::ostream &s, A const&v) { |
| 25 | s << "A{" << v.a << '}'; |
| 26 | return s; |
| 27 | } |
Sergey Lyskov | eae7744 | 2016-05-07 00:26:19 -0400 | [diff] [blame] | 28 | |
Sergey Lyskov | a95bde1 | 2016-05-08 19:31:55 -0400 | [diff] [blame] | 29 | |
| 30 | void init_ex17(py::module &m) { |
| 31 | pybind11::class_<A>(m, "A") |
| 32 | .def(pybind11::init<int>()); |
| 33 | |
| 34 | pybind11::vector_binder<int>(m, "VectorInt"); |
| 35 | |
| 36 | pybind11::vector_binder<A>(m, "VectorA"); |
Sergey Lyskov | eae7744 | 2016-05-07 00:26:19 -0400 | [diff] [blame] | 37 | } |