From cca21eeebcc0958227da37439a9eba6ec1e8ed2f Mon Sep 17 00:00:00 2001 From: "Ralf W. Grosse-Kunstleve" Date: Tue, 9 Jan 2024 17:42:14 -0800 Subject: [PATCH] Expand `PYBIND11_TYPE_CASTER_RVPP` macro. --- include/pybind11/stl.h | 36 +++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/include/pybind11/stl.h b/include/pybind11/stl.h index 0a5aa9cf..2a078d4e 100644 --- a/include/pybind11/stl.h +++ b/include/pybind11/stl.h @@ -420,13 +420,35 @@ struct array_caster { return l.release(); } - PYBIND11_TYPE_CASTER_RVPP(ArrayType, - const_name(const_name(""), const_name("Annotated[")) - + const_name("list[") + value_conv::name + const_name("]") - + const_name(const_name(""), - const_name(", FixedSize(") - + const_name() - + const_name(")]"))); +protected: + ArrayType value; + +public: + static constexpr auto name + = const_name(const_name(""), const_name("Annotated[")) + const_name("list[") + + value_conv::name + const_name("]") + + const_name( + const_name(""), const_name(", FixedSize(") + const_name() + const_name(")]")); + + template >::value, int> = 0> + static handle cast(T_ *src, const return_value_policy_pack &policy, handle parent) { + if (!src) { + return none().release(); + } + if (policy == return_value_policy::take_ownership) { + auto h = cast(std::move(*src), policy, parent); + delete src; + return h; + } + return cast(*src, policy, parent); + } + + operator ArrayType *() { return &value; } + operator ArrayType &() { return value; } + operator ArrayType &&() && { return std::move(value); } + + template + using cast_op_type = movable_cast_op_type; }; template