还有行为和 std::is_constructible 不一致的地方:
class Test {
~Test() = delete ;
};
std::is_constructible<Test,Test>::value ==> false
#include <cstdint>
#include <type_traits>
template<class T>
struct is_reference : std::is_same<T,std::remove_reference_t<T> > {};
template<class T>
inline constexpr bool is_reference_v = ! is_reference<T>::value ;
#if 1
template<class, class T, class... Args>
struct is_constructible_impl : std::false_type {};
template<class T, class... Args>
struct is_constructible_impl< void , T&, Args&...> : std::true_type {};
template<class T, class... Args>
struct is_constructible_impl< void , T&, Args...> : std::false_type {};
template<class T, class... Args>
struct is_constructible_impl< void , T&, Args&&...> : std::false_type {};
template<class T, class... Args>
struct is_constructible_impl< void , T&&, Args...> : std::true_type {};
template<class T, class... Args>
struct is_constructible_impl< void , T&&, Args&...> : std::false_type {};
template<class T, class... Args>
struct is_constructible_impl< void , T&&, Args&&...> : std::true_type {};
template<class T, class... Args>
struct is_constructible_impl<decltype( (new T(std::declval<Args>()...) ), void() ) ,
T, Args...> : std::true_type {};
template<class T, class... Args>
struct is_constructible : is_constructible_impl<void, T, Args...> {};
#else
using std::is_constructible;
#endif
static_assert(is_constructible<int>::value);
static_assert(!is_constructible<intptr_t, int *>::value );
static_assert(is_constructible<int, int>::value);
static_assert(is_constructible<int, int&>::value);
static_assert(is_constructible<int, int&& >::value);
static_assert(is_constructible<int&, int& >::value);
static_assert(!is_constructible<int&, int&& >::value);
static_assert(!is_constructible<int&, int >::value);
static_assert(!is_constructible<int&&, int& >::value);
static_assert( is_constructible<int&&, int >::value);
static_assert( is_constructible<int&&, int&& >::value);
static_assert(is_constructible<int, float>::value);
static_assert(!is_constructible<int, int*>::value);
static_assert(!is_constructible<void, void>::value);
static_assert(!is_constructible<int(int), int(int)>::value);
static_assert(is_constructible<int(*)(), int()>::value);
|