blob: d02ed09f7873fcee9ba83c1001363759f464e402 [file] [log] [blame]
Sergey Lyskoveae77442016-05-07 00:26:19 -04001/*
Jason Rhinelanderb3f3d792016-07-18 16:43:18 -04002 example/example-stl-binder-vector.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
Jason Rhinelanderb3f3d792016-07-18 16:43:18 -040027void init_ex_stl_binder_vector(py::module &m) {
Wenzel Jakoba975ab22016-07-19 17:35:09 +020028 py::class_<El>(m, "El")
29 .def(py::init<int>());
Sergey Lyskova95bde12016-05-08 19:31:55 -040030
Wenzel Jakoba975ab22016-07-19 17:35:09 +020031 py::bind_vector<unsigned int>(m, "VectorInt");
32 py::bind_vector<bool>(m, "VectorBool");
Sergey Lyskova95bde12016-05-08 19:31:55 -040033
Wenzel Jakoba975ab22016-07-19 17:35:09 +020034 py::bind_vector<El>(m, "VectorEl");
Wenzel Jakob25c03ce2016-05-15 20:50:38 +020035
Wenzel Jakoba975ab22016-07-19 17:35:09 +020036 py::bind_vector<std::vector<El>>(m, "VectorVectorEl");
Sergey Lyskoveae77442016-05-07 00:26:19 -040037}