mirror of
https://github.com/pybind/pybind11.git
synced 2026-04-20 06:49:25 +00:00
Implicit conversions to bool + np.bool_ conversion (#925)
This adds support for implicit conversions to bool from Python types with `__bool__` (Python 3) or `__nonzero__` (Python 2) attributes, and adds direct (i.e. non-converting) support for numpy bools.
This commit is contained in:
committed by
Jason Rhinelander
parent
a03408c839
commit
e07f75839d
@@ -116,6 +116,10 @@ TEST_SUBMODULE(builtin_casters, m) {
|
||||
m.def("load_nullptr_t", [](std::nullptr_t) {}); // not useful, but it should still compile
|
||||
m.def("cast_nullptr_t", []() { return std::nullptr_t{}; });
|
||||
|
||||
// test_bool_caster
|
||||
m.def("bool_passthrough", [](bool arg) { return arg; });
|
||||
m.def("bool_passthrough_noconvert", [](bool arg) { return arg; }, py::arg().noconvert());
|
||||
|
||||
// test_reference_wrapper
|
||||
m.def("refwrap_builtin", [](std::reference_wrapper<int> p) { return 10 * p.get(); });
|
||||
m.def("refwrap_usertype", [](std::reference_wrapper<UserType> p) { return p.get().value(); });
|
||||
|
||||
Reference in New Issue
Block a user