From 682606febaf1a00984cf74899b24bc99a0ea8d7c Mon Sep 17 00:00:00 2001 From: aBram Date: Tue, 20 Dec 2022 20:17:54 +0200 Subject: [PATCH] improve is_constructible, is_copy_constructible, is_move_constructible for type traits with default definitions --- include/etl/type_traits.h | 35 +++++++++++++++++++++++------------ test/test_type_traits.cpp | 15 --------------- 2 files changed, 23 insertions(+), 27 deletions(-) diff --git a/include/etl/type_traits.h b/include/etl/type_traits.h index 03a57c1b8..11f46fa4a 100644 --- a/include/etl/type_traits.h +++ b/include/etl/type_traits.h @@ -1980,28 +1980,39 @@ namespace etl { }; + //*************************************************************************** + /// is_convertible + namespace private_type_traits + { + template + struct is_constructible_ : etl::false_type {}; + + template + struct is_constructible_()...))>, T, Args...> : etl::true_type {}; + }; + #if ETL_USING_CPP11 //********************************************* // is_constructible - template - struct is_constructible : public etl::bool_constant::value || etl::is_pointer::value> - { - }; + template + using is_constructible = private_type_traits::is_constructible_, T, Args...>; #endif //********************************************* // is_copy_constructible - template - struct is_copy_constructible : public etl::bool_constant::value || etl::is_pointer::value> - { - }; + template struct is_copy_constructible : public is_constructible::type>::type>{}; + template <> struct is_copy_constructible : public false_type{}; + template <> struct is_copy_constructible : public false_type{}; + template <> struct is_copy_constructible : public false_type{}; + template <> struct is_copy_constructible : public false_type{}; //********************************************* // is_move_constructible - template - struct is_move_constructible : public etl::bool_constant::value || etl::is_pointer::value> - { - }; + template struct is_move_constructible: public is_constructible::type>{}; + template <> struct is_move_constructible : public false_type{}; + template <> struct is_move_constructible : public false_type{}; + template <> struct is_move_constructible : public false_type{}; + template <> struct is_move_constructible : public false_type{}; //********************************************* // is_trivially_constructible diff --git a/test/test_type_traits.cpp b/test/test_type_traits.cpp index 838487572..363d59d98 100644 --- a/test/test_type_traits.cpp +++ b/test/test_type_traits.cpp @@ -127,11 +127,6 @@ struct etl::is_assignable : public etl::true_type { }; -template <> -struct etl::is_constructible : public etl::true_type -{ -}; - template <> struct etl::is_copy_constructible : public etl::true_type { @@ -148,11 +143,6 @@ struct etl::is_assignable : public etl::true_type { }; -template <> -struct etl::is_constructible : public etl::true_type -{ -}; - template <> struct etl::is_copy_constructible : public etl::false_type { @@ -169,11 +159,6 @@ struct etl::is_assignable : public etl::true { }; -template <> -struct etl::is_constructible : public etl::true_type -{ -}; - template <> struct etl::is_copy_constructible : public etl::true_type {