mirror of
https://github.com/pybind/pybind11.git
synced 2024-11-25 22:52:01 +00:00
improved SFINAE in type_caster_generic (closes #70)
This commit is contained in:
parent
92b2f452f0
commit
260bc58f57
@ -209,11 +209,11 @@ public:
|
||||
operator type*() { return (type *) value; }
|
||||
operator type&() { return *((type *) value); }
|
||||
protected:
|
||||
template <typename T = type, typename std::enable_if<std::is_copy_constructible<T>::value, int>::type = 0>
|
||||
template <typename T = type, typename std::enable_if<detail::is_copy_constructible<T>::value, int>::type = 0>
|
||||
static void *copy_constructor(const void *arg) {
|
||||
return new type(*((const type *) arg));
|
||||
}
|
||||
template <typename T = type, typename std::enable_if<!std::is_copy_constructible<T>::value, int>::type = 0>
|
||||
template <typename T = type, typename std::enable_if<!detail::is_copy_constructible<T>::value, int>::type = 0>
|
||||
static void *copy_constructor(const void *) { return nullptr; }
|
||||
};
|
||||
|
||||
|
@ -240,6 +240,14 @@ template <typename T> struct intrinsic_type<T&&> { typedef type
|
||||
template <typename T, size_t N> struct intrinsic_type<const T[N]> { typedef typename intrinsic_type<T>::type type; };
|
||||
template <typename T, size_t N> struct intrinsic_type<T[N]> { typedef typename intrinsic_type<T>::type type; };
|
||||
|
||||
/** \brief SFINAE helper class to check if a copy constructor is usable (in contrast to
|
||||
* std::is_copy_constructible, this class also checks if the 'new' operator is accessible */
|
||||
template <typename T> struct is_copy_constructible {
|
||||
template <typename T2> static std::true_type test(decltype(new T2(std::declval<T2>())) *);
|
||||
template <typename T2> static std::false_type test(...);
|
||||
static const bool value = std::is_same<std::true_type, decltype(test<T>(nullptr))>::value;
|
||||
};
|
||||
|
||||
/// Helper type to replace 'void' in some expressions
|
||||
struct void_type { };
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user