support for opaque types
diff --git a/example/example.cpp b/example/example.cpp
index d84b456..a4fb4d3 100644
--- a/example/example.cpp
+++ b/example/example.cpp
@@ -22,6 +22,7 @@
void init_ex11(py::module &);
void init_ex12(py::module &);
void init_ex13(py::module &);
+void init_ex14(py::module &);
void init_issues(py::module &);
PYBIND11_PLUGIN(example) {
@@ -40,6 +41,7 @@
init_ex11(m);
init_ex12(m);
init_ex13(m);
+ init_ex14(m);
init_issues(m);
return m.ptr();
diff --git a/example/example14.cpp b/example/example14.cpp
new file mode 100644
index 0000000..5c6d918
--- /dev/null
+++ b/example/example14.cpp
@@ -0,0 +1,29 @@
+/*
+ example/example14.cpp -- opaque types
+
+ Copyright (c) 2015 Wenzel Jakob <wenzel@inf.ethz.ch>
+
+ All rights reserved. Use of this source code is governed by a
+ BSD-style license that can be found in the LICENSE file.
+*/
+
+#include "example.h"
+#include <pybind11/stl.h>
+#include <vector>
+
+typedef std::vector<std::string> StringList;
+
+void init_ex14(py::module &m) {
+ py::class_<py::opaque<StringList>>(m, "StringList")
+ .def(py::init<>())
+ .def("push_back", [](py::opaque<StringList> &l, const std::string &str) { l->push_back(str); })
+ .def("pop_back", [](py::opaque<StringList> &l) { l->pop_back(); })
+ .def("back", [](py::opaque<StringList> &l) { return l->back(); });
+
+ m.def("print_opaque_list", [](py::opaque<StringList> &_l) {
+ StringList &l = _l;
+ std::cout << "Opaque list: " << std::endl;
+ for (auto entry : l)
+ std::cout << " " << entry << std::endl;
+ });
+}
diff --git a/example/example14.py b/example/example14.py
new file mode 100644
index 0000000..c9c8665
--- /dev/null
+++ b/example/example14.py
@@ -0,0 +1,14 @@
+from __future__ import print_function
+import sys
+
+sys.path.append('.')
+
+from example import StringList, print_opaque_list
+
+l = StringList()
+l.push_back("Element 1")
+l.push_back("Element 2")
+print_opaque_list(l)
+print("Back element is %s" % l.back())
+l.pop_back()
+print_opaque_list(l)
diff --git a/example/example14.ref b/example/example14.ref
new file mode 100644
index 0000000..d738fef
--- /dev/null
+++ b/example/example14.ref
@@ -0,0 +1,6 @@
+Opaque list:
+ Element 1
+ Element 2
+Back element is Element 2
+Opaque list:
+ Element 1