example17.cpp 662 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
5
6
7
8
9
10
11
12
13

    Copyright (c) 2016 Wenzel Jakob <wenzel.jakob@epfl.ch>

    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"

#include <pybind11/stl_binders.h>

14
15

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

	int a;
Sergey Lyskov's avatar
Sergey Lyskov committed
21
22
23
};


24
25
26
27
28
29
30
31
32
33
34
std::ostream & operator<<(std::ostream &s, A const&v) {
	s << "A{" << v.a << '}';
	return s;
}


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

	pybind11::vector_binder<int>(m, "VectorInt");
Sergey Lyskov's avatar
Sergey Lyskov committed
35

36
	pybind11::vector_binder<A>(m, "VectorA");
Sergey Lyskov's avatar
Sergey Lyskov committed
37
}