mirror of
https://github.com/pybind/pybind11.git
synced 2024-11-22 05:05:11 +00:00
std::array<> caster: support arbitrary sequences
This PR brings the std::array<> caster in sync with the other STL type casters: to accept an arbitrary sequence as input (rather than a list, which is too restrictive).
This commit is contained in:
parent
978d439e92
commit
619fb23056
@ -199,9 +199,9 @@ private:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
bool load(handle src, bool convert) {
|
bool load(handle src, bool convert) {
|
||||||
if (!isinstance<list>(src))
|
if (!isinstance<sequence>(src))
|
||||||
return false;
|
return false;
|
||||||
auto l = reinterpret_borrow<list>(src);
|
auto l = reinterpret_borrow<sequence>(src);
|
||||||
if (!require_size(l.size()))
|
if (!require_size(l.size()))
|
||||||
return false;
|
return false;
|
||||||
size_t ctr = 0;
|
size_t ctr = 0;
|
||||||
|
@ -263,4 +263,6 @@ TEST_SUBMODULE(stl, m) {
|
|||||||
return result;
|
return result;
|
||||||
},
|
},
|
||||||
py::return_value_policy::take_ownership);
|
py::return_value_policy::take_ownership);
|
||||||
|
|
||||||
|
m.def("array_cast_sequence", [](std::array<int, 3> x) { return x; });
|
||||||
}
|
}
|
||||||
|
@ -216,3 +216,7 @@ def test_stl_ownership():
|
|||||||
assert len(r) == 1
|
assert len(r) == 1
|
||||||
del r
|
del r
|
||||||
assert cstats.alive() == 0
|
assert cstats.alive() == 0
|
||||||
|
|
||||||
|
|
||||||
|
def test_array_cast_sequence():
|
||||||
|
assert m.array_cast_sequence((1, 2, 3)) == [1, 2, 3]
|
||||||
|
Loading…
Reference in New Issue
Block a user