@@ -1560,6 +1560,7 @@ struct smart_holder_type_caster<std::unique_ptr<T const>> : smart_holder_type_ca
1560
1560
operator std::unique_ptr<T const >() { return this ->loaded_as_unique_ptr (); }
1561
1561
};
1562
1562
1563
+ #ifndef PYBIND11_USE_SMART_HOLDER_AS_DEFAULT
1563
1564
#define PYBIND11_SMART_HOLDER_TYPE_CASTERS (T ) \
1564
1565
namespace pybind11 { \
1565
1566
namespace detail { \
@@ -1579,10 +1580,36 @@ struct smart_holder_type_caster<std::unique_ptr<T const>> : smart_holder_type_ca
1579
1580
: public smart_holder_type_caster<std::unique_ptr<T const >> {}; \
1580
1581
} \
1581
1582
}
1583
+ #endif
1582
1584
1583
1585
// DETAIL/SMART_HOLDER_TYPE_CASTERS_H///////////////////////////////////////////////////////////////
1584
1586
1587
+ #ifndef PYBIND11_USE_SMART_HOLDER_AS_DEFAULT
1588
+
1585
1589
template <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
+
1586
1613
template <typename type> using make_caster = type_caster<intrinsic_t <type>>;
1587
1614
1588
1615
// 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> {
2227
2254
holder_type holder;
2228
2255
};
2229
2256
2257
+ #ifndef PYBIND11_USE_SMART_HOLDER_AS_DEFAULT
2230
2258
// / Specialize for the common std::shared_ptr, so users don't need to
2231
2259
template <typename T>
2232
2260
class type_caster <std::shared_ptr<T>> : public copyable_holder_caster<T, std::shared_ptr<T>> { };
2261
+ #endif
2233
2262
2234
2263
template <typename type, typename holder_type>
2235
2264
struct move_only_holder_caster {
@@ -2243,9 +2272,11 @@ struct move_only_holder_caster {
2243
2272
static constexpr auto name = type_caster_base<type>::name;
2244
2273
};
2245
2274
2275
+ #ifndef PYBIND11_USE_SMART_HOLDER_AS_DEFAULT
2246
2276
template <typename type, typename deleter>
2247
2277
class type_caster <std::unique_ptr<type, deleter>>
2248
2278
: public move_only_holder_caster<type, std::unique_ptr<type, deleter>> { };
2279
+ #endif
2249
2280
2250
2281
template <typename type, typename holder_type>
2251
2282
using type_caster_holder = conditional_t <is_copy_constructible<holder_type>::value,
0 commit comments