Move reference_wrapper test from test_issues to test_python_types
test_issues is deprecated, and the following commit adds other, related
reference_wrapper tests.
diff --git a/tests/test_issues.cpp b/tests/test_issues.cpp
index 7da3700..cab9ddf 100644
--- a/tests/test_issues.cpp
+++ b/tests/test_issues.cpp
@@ -117,19 +117,6 @@
.def(py::init<int>())
.def("__repr__", [](const Placeholder &p) { return "Placeholder[" + std::to_string(p.i) + "]"; });
- // #171: Can't return reference wrappers (or STL datastructures containing them)
- m2.def("return_vec_of_reference_wrapper", [](std::reference_wrapper<Placeholder> p4) {
- Placeholder *p1 = new Placeholder{1};
- Placeholder *p2 = new Placeholder{2};
- Placeholder *p3 = new Placeholder{3};
- std::vector<std::reference_wrapper<Placeholder>> v;
- v.push_back(std::ref(*p1));
- v.push_back(std::ref(*p2));
- v.push_back(std::ref(*p3));
- v.push_back(p4);
- return v;
- });
-
// #181: iterator passthrough did not compile
m2.def("iterator_passthrough", [](py::iterator s) -> py::iterator {
return py::make_iterator(std::begin(s), std::end(s));
diff --git a/tests/test_issues.py b/tests/test_issues.py
index e60b5ca..08678cf 100644
--- a/tests/test_issues.py
+++ b/tests/test_issues.py
@@ -32,14 +32,6 @@
assert dispatch_issue_go(b) == "Yay.."
-def test_reference_wrapper():
- """#171: Can't return reference wrappers (or STL data structures containing them)"""
- from pybind11_tests.issues import Placeholder, return_vec_of_reference_wrapper
-
- assert str(return_vec_of_reference_wrapper(Placeholder(4))) == \
- "[Placeholder[1], Placeholder[2], Placeholder[3], Placeholder[4]]"
-
-
def test_iterator_passthrough():
"""#181: iterator passthrough did not compile"""
from pybind11_tests.issues import iterator_passthrough
diff --git a/tests/test_python_types.cpp b/tests/test_python_types.cpp
index f3375c6..c9f35f7 100644
--- a/tests/test_python_types.cpp
+++ b/tests/test_python_types.cpp
@@ -560,6 +560,25 @@
m.def("load_nullptr_t", [](std::nullptr_t) {}); // not useful, but it should still compile
m.def("cast_nullptr_t", []() { return std::nullptr_t{}; });
+
+ struct IntWrapper { int i; IntWrapper(int i) : i(i) { } };
+ py::class_<IntWrapper>(m, "IntWrapper")
+ .def(py::init<int>())
+ .def("__repr__", [](const IntWrapper &p) { return "IntWrapper[" + std::to_string(p.i) + "]"; });
+
+ // #171: Can't return reference wrappers (or STL datastructures containing them)
+ m.def("return_vec_of_reference_wrapper", [](std::reference_wrapper<IntWrapper> p4) {
+ IntWrapper *p1 = new IntWrapper{1};
+ IntWrapper *p2 = new IntWrapper{2};
+ IntWrapper *p3 = new IntWrapper{3};
+ std::vector<std::reference_wrapper<IntWrapper>> v;
+ v.push_back(std::ref(*p1));
+ v.push_back(std::ref(*p2));
+ v.push_back(std::ref(*p3));
+ v.push_back(p4);
+ return v;
+ });
+
});
#if defined(_MSC_VER)
diff --git a/tests/test_python_types.py b/tests/test_python_types.py
index f7c3d55..0e563ee 100644
--- a/tests/test_python_types.py
+++ b/tests/test_python_types.py
@@ -606,3 +606,15 @@
assert m.load_nullptr_t(None) is None
assert m.cast_nullptr_t() is None
+
+
+def test_reference_wrapper():
+ """std::reference_wrapper<T> tests.
+
+ #171: Can't return reference wrappers (or STL data structures containing them)
+ """
+ from pybind11_tests import IntWrapper, return_vec_of_reference_wrapper
+
+ # 171:
+ assert str(return_vec_of_reference_wrapper(IntWrapper(4))) == \
+ "[IntWrapper[1], IntWrapper[2], IntWrapper[3], IntWrapper[4]]"