Skip to content

Commit

Permalink
consume(std::unique_ptr<T>&&)
Browse files Browse the repository at this point in the history
  • Loading branch information
rhaschke committed Dec 30, 2019
1 parent 98ea003 commit 1562920
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
9 changes: 7 additions & 2 deletions tests/test_move_arg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ PYBIND11_MODULE(test_move_arg, m) {
}, py::call_guard<py::scoped_ostream_redirect>());
#endif

m.def("working", [](int&& a) { std::cout << a << "\n"; },
py::call_guard<py::scoped_ostream_redirect>());
m.def("consume", [](std::unique_ptr<Item>&& item) {
std::cout << "consume " << *item.get() << "\n";
std::unique_ptr<Item> sink(std::move(item));
std::cout << " old: " << item.get() << "\n new: " << *sink.get() << "\n";
}, py::call_guard<py::scoped_ostream_redirect>());

m.def("consume_str", [](std::string&& s) { std::string o(std::move(s)); });
}
13 changes: 11 additions & 2 deletions tests/test_move_arg.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pytest
from test_move_arg import Item, access
from test_move_arg import *


def test():
Expand All @@ -10,5 +10,14 @@ def test():
del item
print(other)

def test_produce():
item = Item(42)
access(item)
consume(item)
access(item)

def test_foo():
foo()

if __name__ == "__main__":
test()
test_produce()

0 comments on commit 1562920

Please sign in to comment.