test_stl_binders.cpp 797 Bytes
Newer Older
Sergey Lyskov's avatar
Sergey Lyskov committed
1
/*
Dean Moldovan's avatar
Dean Moldovan committed
2
    tests/test_stl_binders.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

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

Dean Moldovan's avatar
Dean Moldovan committed
10
#include "pybind11_tests.h"
Sergey Lyskov's avatar
Sergey Lyskov committed
11

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
std::ostream & operator<<(std::ostream &s, El const&v) {
23
24
    s << "El{" << v.a << '}';
    return s;
25
26
}

27
test_initializer stl_binder_vector([](py::module &m) {
28
29
    py::class_<El>(m, "El")
        .def(py::init<int>());
30

31
32
    py::bind_vector<unsigned int>(m, "VectorInt");
    py::bind_vector<bool>(m, "VectorBool");
33

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

36
    py::bind_vector<std::vector<El>>(m, "VectorVectorEl");
37
});