example17.cpp 716 Bytes
Newer Older
Sergey Lyskov's avatar
Sergey Lyskov committed
1
/*
2
    example/example17.cpp -- Usage of stl_binders functions
Sergey Lyskov's avatar
Sergey Lyskov committed
3

4
    Copyright (c) 2016 Sergey Lyskov
Sergey Lyskov's avatar
Sergey Lyskov committed
5
6
7
8
9
10
11

    All rights reserved. Use of this source code is governed by a
    BSD-style license that can be found in the LICENSE file.
*/

#include "example.h"

12
#include <pybind11/stl_bind.h>
Sergey Lyskov's avatar
Sergey Lyskov committed
13

14
class El {
Sergey Lyskov's avatar
Sergey Lyskov committed
15
public:
16
17
	El() = delete;
	El(int v) : a(v) { }
18
19

	int a;
Sergey Lyskov's avatar
Sergey Lyskov committed
20
21
};

22
23
std::ostream & operator<<(std::ostream &s, El const&v) {
	s << "El{" << v.a << '}';
24
25
26
27
	return s;
}

void init_ex17(py::module &m) {
28
	pybind11::class_<El>(m, "El")
29
30
		.def(pybind11::init<int>());

Wenzel Jakob's avatar
Wenzel Jakob committed
31
	pybind11::bind_vector<unsigned int>(m, "VectorInt");
32
33

	pybind11::bind_vector<El>(m, "VectorEl");
Sergey Lyskov's avatar
Sergey Lyskov committed
34

35
    pybind11::bind_vector<std::vector<El>>(m, "VectorVectorEl");
Sergey Lyskov's avatar
Sergey Lyskov committed
36
}