@@ -1560,6 +1560,7 @@ struct smart_holder_type_caster<std::unique_ptr<T const>> : smart_holder_type_ca
15601560 operator std::unique_ptr<T const >() { return this ->loaded_as_unique_ptr (); }
15611561};
15621562
1563+ #ifndef PYBIND11_USE_SMART_HOLDER_AS_DEFAULT
15631564#define PYBIND11_SMART_HOLDER_TYPE_CASTERS (T ) \
15641565 namespace pybind11 { \
15651566 namespace detail { \
@@ -1579,10 +1580,36 @@ struct smart_holder_type_caster<std::unique_ptr<T const>> : smart_holder_type_ca
15791580 : public smart_holder_type_caster<std::unique_ptr<T const >> {}; \
15801581 } \
15811582 }
1583+ #endif
15821584
15831585// DETAIL/SMART_HOLDER_TYPE_CASTERS_H///////////////////////////////////////////////////////////////
15841586
1587+ #ifndef PYBIND11_USE_SMART_HOLDER_AS_DEFAULT
1588+
15851589template <typename type, typename SFINAE = void > class type_caster : public type_caster_base <type> { };
1590+
1591+ #else
1592+
1593+ template <typename type, typename SFINAE = void > class type_caster : public smart_holder_type_caster <type> {};
1594+
1595+ template <typename T>
1596+ class type_caster <std::shared_ptr<T>> : public smart_holder_type_caster<std::shared_ptr<T>> {};
1597+
1598+ template <typename T>
1599+ class type_caster <std::shared_ptr<T const >>
1600+ : public smart_holder_type_caster<std::shared_ptr<T const >> {};
1601+
1602+ template <typename T>
1603+ class type_caster <std::unique_ptr<T>> : public smart_holder_type_caster<std::unique_ptr<T>> {};
1604+
1605+ template <typename T>
1606+ class type_caster <std::unique_ptr<T const >>
1607+ : public smart_holder_type_caster<std::unique_ptr<T const >> {};
1608+
1609+ #define PYBIND11_SMART_HOLDER_TYPE_CASTERS (T )
1610+
1611+ #endif
1612+
15861613template <typename type> using make_caster = type_caster<intrinsic_t <type>>;
15871614
15881615// Shortcut for calling a caster's `cast_op_type` cast operator for casting a type_caster to a T
@@ -2227,9 +2254,11 @@ struct copyable_holder_caster : public type_caster_base<type> {
22272254 holder_type holder;
22282255};
22292256
2257+ #ifndef PYBIND11_USE_SMART_HOLDER_AS_DEFAULT
22302258// / Specialize for the common std::shared_ptr, so users don't need to
22312259template <typename T>
22322260class type_caster <std::shared_ptr<T>> : public copyable_holder_caster<T, std::shared_ptr<T>> { };
2261+ #endif
22332262
22342263template <typename type, typename holder_type>
22352264struct move_only_holder_caster {
@@ -2243,9 +2272,11 @@ struct move_only_holder_caster {
22432272 static constexpr auto name = type_caster_base<type>::name;
22442273};
22452274
2275+ #ifndef PYBIND11_USE_SMART_HOLDER_AS_DEFAULT
22462276template <typename type, typename deleter>
22472277class type_caster <std::unique_ptr<type, deleter>>
22482278 : public move_only_holder_caster<type, std::unique_ptr<type, deleter>> { };
2279+ #endif
22492280
22502281template <typename type, typename holder_type>
22512282using type_caster_holder = conditional_t <is_copy_constructible<holder_type>::value,
0 commit comments