From 260bc58f574498791c027b9ad4d4e5ccdcf2d568 Mon Sep 17 00:00:00 2001 From: Wenzel Jakob Date: Mon, 18 Jan 2016 21:00:25 +0100 Subject: [PATCH] improved SFINAE in type_caster_generic (closes #70) --- include/pybind11/cast.h | 4 ++-- include/pybind11/common.h | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/include/pybind11/cast.h b/include/pybind11/cast.h index bc26e4777..909ce1418 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 a0af6787d..7122d80ce 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 { };