mirror of
https://github.com/pybind/pybind11.git
synced 2026-05-13 01:36:21 +00:00
returning unique pointers is now allowed
This commit is contained in:
@@ -31,4 +31,10 @@ void init_ex14(py::module &m) {
|
||||
m.def("print_void_ptr", [](void *ptr) { std::cout << "Got void ptr : " << (uint64_t) ptr << std::endl; });
|
||||
m.def("return_null_str", []() { return (char *) nullptr; });
|
||||
m.def("print_null_str", [](char *ptr) { std::cout << "Got null str : " << (uint64_t) ptr << std::endl; });
|
||||
|
||||
m.def("return_unique_ptr", []() -> std::unique_ptr<StringList> {
|
||||
StringList *result = new StringList();
|
||||
result->push_back("some value");
|
||||
return std::unique_ptr<StringList>(result);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ sys.path.append('.')
|
||||
from example import StringList, print_opaque_list
|
||||
from example import return_void_ptr, print_void_ptr
|
||||
from example import return_null_str, print_null_str
|
||||
from example import return_unique_ptr
|
||||
|
||||
l = StringList()
|
||||
l.push_back("Element 1")
|
||||
@@ -19,3 +20,5 @@ print_void_ptr(return_void_ptr())
|
||||
|
||||
print(return_null_str())
|
||||
print_null_str(return_null_str())
|
||||
|
||||
print(return_unique_ptr())
|
||||
|
||||
@@ -7,3 +7,4 @@ Opaque list:
|
||||
Got void ptr : 1234
|
||||
None
|
||||
Got null str : 0
|
||||
[u'some value']
|
||||
|
||||
Reference in New Issue
Block a user