mirror of
https://github.com/pybind/pybind11.git
synced 2024-11-22 05:05:11 +00:00
Adding holder_caster typename SFINAE = void
hooks to help work around the current lack of smart-pointer interoperability (#2833)
* Adding move_only_holder_caster `typename SFINAE = void` to enable external specializations. * Adding SFINAE hook also to copyable_holder_caster, for uniformity, with comment to explain the purpose.
This commit is contained in:
parent
23c3edcf21
commit
932769b038
@ -1525,7 +1525,11 @@ struct holder_helper {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/// Type caster for holder types like std::shared_ptr, etc.
|
/// Type caster for holder types like std::shared_ptr, etc.
|
||||||
template <typename type, typename holder_type>
|
/// The SFINAE hook is provided to help work around the current lack of support
|
||||||
|
/// for smart-pointer interoperability. Please consider it an implementation
|
||||||
|
/// detail that may change in the future, as formal support for smart-pointer
|
||||||
|
/// interoperability is added into pybind11.
|
||||||
|
template <typename type, typename holder_type, typename SFINAE = void>
|
||||||
struct copyable_holder_caster : public type_caster_base<type> {
|
struct copyable_holder_caster : public type_caster_base<type> {
|
||||||
public:
|
public:
|
||||||
using base = type_caster_base<type>;
|
using base = type_caster_base<type>;
|
||||||
@ -1600,7 +1604,10 @@ protected:
|
|||||||
template <typename T>
|
template <typename T>
|
||||||
class type_caster<std::shared_ptr<T>> : public copyable_holder_caster<T, std::shared_ptr<T>> { };
|
class type_caster<std::shared_ptr<T>> : public copyable_holder_caster<T, std::shared_ptr<T>> { };
|
||||||
|
|
||||||
template <typename type, typename holder_type>
|
/// Type caster for holder types like std::unique_ptr.
|
||||||
|
/// Please consider the SFINAE hook an implementation detail, as explained
|
||||||
|
/// in the comment for the copyable_holder_caster.
|
||||||
|
template <typename type, typename holder_type, typename SFINAE = void>
|
||||||
struct move_only_holder_caster {
|
struct move_only_holder_caster {
|
||||||
static_assert(std::is_base_of<type_caster_base<type>, type_caster<type>>::value,
|
static_assert(std::is_base_of<type_caster_base<type>, type_caster<type>>::value,
|
||||||
"Holder classes are only supported for custom types");
|
"Holder classes are only supported for custom types");
|
||||||
|
Loading…
Reference in New Issue
Block a user