mirror of
https://github.com/pybind/pybind11.git
synced 2026-04-20 14:59:27 +00:00
cast pointer to std::tuple and std::pair (#2334)
This commit is contained in:
@@ -117,12 +117,16 @@ TEST_SUBMODULE(builtin_casters, m) {
|
||||
return std::make_pair(RValueCaster{}, std::make_tuple(RValueCaster{}, std::make_pair(RValueCaster{}, RValueCaster{}))); });
|
||||
m.def("lvalue_nested", []() -> const decltype(lvnested) & { return lvnested; });
|
||||
|
||||
static std::pair<int, std::string> int_string_pair{2, "items"};
|
||||
m.def("int_string_pair", []() { return &int_string_pair; });
|
||||
|
||||
// test_builtins_cast_return_none
|
||||
m.def("return_none_string", []() -> std::string * { return nullptr; });
|
||||
m.def("return_none_char", []() -> const char * { return nullptr; });
|
||||
m.def("return_none_bool", []() -> bool * { return nullptr; });
|
||||
m.def("return_none_int", []() -> int * { return nullptr; });
|
||||
m.def("return_none_float", []() -> float * { return nullptr; });
|
||||
m.def("return_none_pair", []() -> std::pair<int,int> * { return nullptr; });
|
||||
|
||||
// test_none_deferred
|
||||
m.def("defer_none_cstring", [](char *) { return false; });
|
||||
|
||||
@@ -250,6 +250,8 @@ def test_tuple(doc):
|
||||
assert m.rvalue_nested() == ("rvalue", ("rvalue", ("rvalue", "rvalue")))
|
||||
assert m.lvalue_nested() == ("lvalue", ("lvalue", ("lvalue", "lvalue")))
|
||||
|
||||
assert m.int_string_pair() == (2, "items")
|
||||
|
||||
|
||||
def test_builtins_cast_return_none():
|
||||
"""Casters produced with PYBIND11_TYPE_CASTER() should convert nullptr to None"""
|
||||
@@ -258,6 +260,7 @@ def test_builtins_cast_return_none():
|
||||
assert m.return_none_bool() is None
|
||||
assert m.return_none_int() is None
|
||||
assert m.return_none_float() is None
|
||||
assert m.return_none_pair() is None
|
||||
|
||||
|
||||
def test_none_deferred():
|
||||
|
||||
Reference in New Issue
Block a user