diff --git a/include/pybind11/cast.h b/include/pybind11/cast.h index bc26e477..909ce141 100644 --- a/include/pybind11/cast.h +++ b/include/pybind11/cast.h @@ -209,11 +209,11 @@ public: operator type*() { return (type *) value; } operator type&() { return *((type *) value); } protected: - template ::value, int>::type = 0> + template ::value, int>::type = 0> static void *copy_constructor(const void *arg) { return new type(*((const type *) arg)); } - template ::value, int>::type = 0> + template ::value, int>::type = 0> static void *copy_constructor(const void *) { return nullptr; } }; diff --git a/include/pybind11/common.h b/include/pybind11/common.h index a0af6787..7122d80c 100644 --- a/include/pybind11/common.h +++ b/include/pybind11/common.h @@ -240,6 +240,14 @@ template struct intrinsic_type { typedef type template struct intrinsic_type { typedef typename intrinsic_type::type type; }; template struct intrinsic_type { typedef typename intrinsic_type::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 struct is_copy_constructible { + template static std::true_type test(decltype(new T2(std::declval())) *); + template static std::false_type test(...); + static const bool value = std::is_same(nullptr))>::value; +}; + /// Helper type to replace 'void' in some expressions struct void_type { };