blob: 8ae4cad088c91d7b3046116389fa07494876dddd [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
Wenzel Jakob25c03ce2016-05-15 20:50:38 +02004 Copyright (c) 2016 Sergey Lyskov
Sergey Lyskoveae77442016-05-07 00:26:19 -04005
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
Wenzel Jakob25c03ce2016-05-15 20:50:38 +020012#include <pybind11/stl_bind.h>
Sergey Lyskoveae77442016-05-07 00:26:19 -040013
Wenzel Jakob25c03ce2016-05-15 20:50:38 +020014class El {
Sergey Lyskoveae77442016-05-07 00:26:19 -040015public:
Wenzel Jakob25c03ce2016-05-15 20:50:38 +020016 El() = delete;
17 El(int v) : a(v) { }
Sergey Lyskova95bde12016-05-08 19:31:55 -040018
19 int a;
Sergey Lyskoveae77442016-05-07 00:26:19 -040020};
21
Wenzel Jakob25c03ce2016-05-15 20:50:38 +020022std::ostream & operator<<(std::ostream &s, El const&v) {
23 s << "El{" << v.a << '}';
Sergey Lyskova95bde12016-05-08 19:31:55 -040024 return s;
25}
Sergey Lyskoveae77442016-05-07 00:26:19 -040026
Sergey Lyskova95bde12016-05-08 19:31:55 -040027void init_ex17(py::module &m) {
Wenzel Jakob25c03ce2016-05-15 20:50:38 +020028 pybind11::class_<El>(m, "El")
Sergey Lyskova95bde12016-05-08 19:31:55 -040029 .def(pybind11::init<int>());
30
Wenzel Jakob00c7d6c2016-05-16 12:14:25 +020031 pybind11::bind_vector<unsigned int>(m, "VectorInt");
Sergey Lyskova95bde12016-05-08 19:31:55 -040032
Wenzel Jakob25c03ce2016-05-15 20:50:38 +020033 pybind11::bind_vector<El>(m, "VectorEl");
34
35 pybind11::bind_vector<std::vector<El>>(m, "VectorVectorEl");
Sergey Lyskoveae77442016-05-07 00:26:19 -040036}