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