@@ -0,0 +1,31 @@ |
|
|
|
1 |
+#include "test_move_arg.h" |
|
2 |
+#include <pybind11/pybind11.h> |
|
3 |
+#include <pybind11/iostream.h> |
|
4 |
+#include <sstream> |
|
5 |
+ |
|
6 |
+namespace py = pybind11; |
|
7 |
+ |
|
8 |
+PYBIND11_MODULE(test_move_arg, m) { |
|
9 |
+ py::class_(m, "Item") |
|
10 |
+ .def(py::init<int>(), py::call_guardpy::scoped\_ostream\_redirect()) |
|
11 |
+ .def("__repr__", [](const Item& item) { |
|
12 |
+ std::stringstream ss; |
|
13 |
+ ss << "py " << item; |
|
14 |
+return ss.str(); |
|
15 |
+ }, py::call_guardpy::scoped\_ostream\_redirect()); |
|
16 |
+ |
|
17 |
+ m.def("access", [](const Item& item) { |
|
18 |
+ std::cout << "access " << item << "\n"; |
|
19 |
+ }, py::call_guardpy::scoped\_ostream\_redirect()); |
|
20 |
+ |
|
21 |
+#if 0 // rvalue arguments fail during compilation |
|
22 |
+ m.def("consume", [](Item&& item) { |
|
23 |
+ std::cout << "consume " << item << "\n "; |
|
24 |
+ Item sink(std::move(item)); |
|
25 |
+ std::cout << " old: " << item << "\n new: " << sink << "\n"; |
|
26 |
+ }, py::call_guardpy::scoped\_ostream\_redirect()); |
|
27 |
+#endif |
|
28 |
+ |
|
29 |
+ m.def("working", [](int&& a) { std::cout << a << "\n"; }, |
|
30 |
+ py::call_guardpy::scoped\_ostream\_redirect()); |
|
31 |
+} |