blob: 8370b5c688db519a6489523f413b4ba6a71eafae [file] [log] [blame]
Sergey Lyskoveae77442016-05-07 00:26:19 -04001/*
Sergey Lyskova95bde12016-05-08 19:31:55 -04002 example/example17.cpp -- Usage of stl_binders functions
Sergey Lyskoveae77442016-05-07 00:26:19 -04003
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 Lyskova95bde12016-05-08 19:31:55 -040014
15class A {
Sergey Lyskoveae77442016-05-07 00:26:19 -040016public:
17 A() = delete;
Sergey Lyskova95bde12016-05-08 19:31:55 -040018 A(int v) :a(v) {}
19
20 int a;
Sergey Lyskoveae77442016-05-07 00:26:19 -040021};
22
Sergey Lyskoveae77442016-05-07 00:26:19 -040023
Sergey Lyskova95bde12016-05-08 19:31:55 -040024std::ostream & operator<<(std::ostream &s, A const&v) {
25 s << "A{" << v.a << '}';
26 return s;
27}
Sergey Lyskoveae77442016-05-07 00:26:19 -040028
Sergey Lyskova95bde12016-05-08 19:31:55 -040029
30void 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 Lyskoveae77442016-05-07 00:26:19 -040037}