Commit 25c03cec by Wenzel Jakob

stl_bind redesign & cleanup pass

parent 26aca3d8
......@@ -108,6 +108,7 @@ set(PYBIND11_HEADERS
include/pybind11/pybind11.h
include/pybind11/pytypes.h
include/pybind11/stl.h
include/pybind11/stl_bind.h
include/pybind11/typeid.h
)
......
......@@ -99,6 +99,7 @@ Jonas Adler,
Sylvain Corlay,
Axel Huebl,
@hulucc,
Sergey Lyskov
Johan Mabille,
Tomasz Miąsko, and
Ben Pritchard.
......
/*
example/example17.cpp -- Usage of stl_binders functions
Copyright (c) 2016 Wenzel Jakob <wenzel.jakob@epfl.ch>
Copyright (c) 2016 Sergey Lyskov
All rights reserved. Use of this source code is governed by a
BSD-style license that can be found in the LICENSE file.
......@@ -9,29 +9,28 @@
#include "example.h"
#include <pybind11/stl_binders.h>
#include <pybind11/stl_bind.h>
class A {
class El {
public:
A() = delete;
A(int v) :a(v) {}
El() = delete;
El(int v) : a(v) { }
int a;
};
std::ostream & operator<<(std::ostream &s, A const&v) {
s << "A{" << v.a << '}';
std::ostream & operator<<(std::ostream &s, El const&v) {
s << "El{" << v.a << '}';
return s;
}
void init_ex17(py::module &m) {
pybind11::class_<A>(m, "A")
pybind11::class_<El>(m, "El")
.def(pybind11::init<int>());
pybind11::vector_binder<int>(m, "VectorInt");
pybind11::bind_vector<int>(m, "VectorInt");
pybind11::bind_vector<El>(m, "VectorEl");
pybind11::vector_binder<A>(m, "VectorA");
pybind11::bind_vector<std::vector<El>>(m, "VectorVectorEl");
}
#!/usr/bin/env python
from __future__ import print_function
from example import VectorInt, VectorA, A
from example import VectorInt, El, VectorEl, VectorVectorEl
v_int = VectorInt(2)
v_int = VectorInt([0, 0])
print(len(v_int))
print(bool(v_int))
v_int2 = VectorInt(2)
v_int2 = VectorInt([0, 0])
print(v_int == v_int2)
v_int2[1] = 1
......@@ -24,8 +24,17 @@ print(v_int2)
v_int.append(99)
v_int2[2:-2] = v_int
print(v_int2)
del v_int2[1:3]
print(v_int2)
del v_int2[0]
print(v_int2)
v_a = VectorA()
v_a.append(A(1))
v_a.append(A(2))
v_a = VectorEl()
v_a.append(El(1))
v_a.append(El(2))
print(v_a)
vv_a = VectorVectorEl()
vv_a.append(v_a)
vv_b = vv_a[0]
print(vv_b)
......@@ -4,8 +4,7 @@ True
True
VectorInt[3, 2, 1, 0, 1, 2, 3]
VectorInt[3, 2, 0, 0, 99, 2, 3]
A constructor
A destructor
A constructor
A destructor
VectorA[A{1}, A{2}]
VectorInt[3, 0, 99, 2, 3]
VectorInt[0, 99, 2, 3]
VectorEl[El{1}, El{2}]
VectorEl[El{1}, El{2}]
......@@ -212,7 +212,7 @@ protected:
rec->is_constructor = !strcmp(rec->name, "__init__");
rec->has_args = false;
rec->has_kwargs = false;
rec->nargs = args;
rec->nargs = (uint16_t) args;
#if PY_MAJOR_VERSION < 3
if (rec->sibling && PyMethod_Check(rec->sibling.ptr()))
......
......@@ -24,6 +24,7 @@ setup(
'include/pybind11/numpy.h',
'include/pybind11/pybind11.h',
'include/pybind11/stl.h',
'include/pybind11/stl_bind.h',
'include/pybind11/common.h',
'include/pybind11/functional.h',
'include/pybind11/operators.h',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment