From a7786e08afde7026b21d44a5f9d01b2e25ebf527 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Thu, 5 Aug 2021 09:23:02 +0100 Subject: [PATCH] Updated type traits generator --- .../etl/generators/type_traits_generator.h | 139 +++++++++++++----- include/etl/type_traits.h | 74 +++++----- 2 files changed, 139 insertions(+), 74 deletions(-) diff --git a/include/etl/generators/type_traits_generator.h b/include/etl/generators/type_traits_generator.h index 24653e00..4716f9ed 100644 --- a/include/etl/generators/type_traits_generator.h +++ b/include/etl/generators/type_traits_generator.h @@ -471,10 +471,10 @@ namespace etl template <> struct make_signed { typedef etl::conditional::type>::type type; + int16_t, + etl::conditional::type>::type type; }; template <> struct make_signed { typedef short type; }; @@ -500,10 +500,10 @@ namespace etl template <> struct make_unsigned { typedef etl::conditional::type>::type type; + uint16_t, + etl::conditional::type>::type type; }; template <> struct make_unsigned { typedef unsigned int type; }; @@ -1211,6 +1211,7 @@ namespace etl ///\ingroup type_traits template struct alignment_of : std::alignment_of {}; template <> struct alignment_of : std::integral_constant {}; + template <> struct alignment_of : std::integral_constant {}; #if ETL_CPP17_SUPPORTED template @@ -1565,7 +1566,7 @@ namespace etl struct is_trivially_constructible; #endif - //*************************************************************************** + //********************************************* // is_trivially_copy_constructible #if ETL_CPP11_TYPE_TRAITS_IS_TRIVIAL_SUPPORTED template @@ -1585,7 +1586,7 @@ namespace etl struct is_trivially_copy_constructible; #endif - //*************************************************************************** + //********************************************* // is_trivially_destructible #if ETL_CPP11_TYPE_TRAITS_IS_TRIVIAL_SUPPORTED template @@ -1605,7 +1606,7 @@ namespace etl struct is_trivially_destructible; #endif - //*************************************************************************** + //********************************************* // is_trivially_copy_assignable #if ETL_CPP11_TYPE_TRAITS_IS_TRIVIAL_SUPPORTED template @@ -1625,7 +1626,7 @@ namespace etl struct is_trivially_copy_assignable; #endif - //*************************************************************************** + //********************************************* // is_trivially_copyable #if ETL_CPP11_TYPE_TRAITS_IS_TRIVIAL_SUPPORTED template @@ -1645,7 +1646,7 @@ namespace etl struct is_trivially_copyable; #endif -#elif defined(ETL_USE_TYPE_TRAITS_BUILTINS) +#elif defined(ETL_USE_TYPE_TRAITS_BUILTINS) && !defined(ETL_USER_DEFINED_TYPE_TRAITS) //********************************************* // Use the compiler's builtins. @@ -1654,23 +1655,41 @@ namespace etl //********************************************* // is_assignable template - struct is_assignable : public etl::bool_constant<__is_assignable(T1, T2)> + struct is_assignable { + static ETL_CONSTANT bool value = __is_assignable(T1, T2); }; #if ETL_CPP11_SUPPORTED //********************************************* // is_constructible template - struct is_constructible : public etl::bool_constant<__is_constructible(T, TArgs...)> + struct is_constructible { + static ETL_CONSTANT bool value = __is_constructible(T, TArgs...); + }; +#else + //********************************************* + // is_constructible + template + struct is_constructible + { + static ETL_CONSTANT bool value = __is_constructible(T, TArgs); + }; + + //********************************************* + // is_constructible + template + struct is_constructible + { + static ETL_CONSTANT bool value = __is_constructible(T); }; #endif //********************************************* // is_copy_constructible template - struct is_copy_constructible : public etl::is_constructible> + struct is_copy_constructible : public etl::is_constructible::type> { }; @@ -1681,42 +1700,88 @@ namespace etl { }; +#if ETL_CPP11_SUPPORTED + //********************************************* + // is_trivially_constructible + template + struct is_trivially_constructible + { +#if defined(ETL_COMPILER_GCC) + static ETL_CONSTANT bool value = __has_trivial_constructor(T); +#else + static ETL_CONSTANT bool value = __is_trivially_constructible(T, TArgs...); +#endif + }; +#else + //********************************************* + // is_trivially_constructible + template + struct is_trivially_constructible + { +#if defined(ETL_COMPILER_GCC) + static ETL_CONSTANT bool value = __has_trivial_constructor(T); +#else + static ETL_CONSTANT bool value = __is_trivially_constructible(T, TArgs); +#endif + }; + //********************************************* // is_trivially_constructible template - struct is_trivially_constructible : public etl::bool_constant<__is_trivially_constructible(T)> + struct is_trivially_constructible { +#if defined(ETL_COMPILER_GCC) + static ETL_CONSTANT bool value = __has_trivial_constructor(T); +#else + static ETL_CONSTANT bool value = __is_trivially_constructible(T); +#endif }; +#endif - //*************************************************************************** + //********************************************* // is_trivially_copy_constructible template - struct is_trivially_copy_constructible : public etl::bool_constant<__is_trivially_copyable(T)> + struct is_trivially_copy_constructible : public is_trivially_constructible::type> { }; - //*************************************************************************** + //********************************************* // is_trivially_destructible template - struct is_trivially_destructible : public etl::bool_constant<__is_trivially_destructible(T)> + struct is_trivially_destructible { +#if defined(ETL_COMPILER_GCC) + static ETL_CONSTANT bool value = __has_trivial_destructor(T); +#else + static ETL_CONSTANT bool value = __is_trivially_destructible(T); +#endif }; - //*************************************************************************** + //********************************************* // is_trivially_copy_assignable template - struct is_trivially_copy_assignable : public etl::bool_constant<__is_trivially_copyable(T)> + struct is_trivially_copy_assignable { +#if defined(ETL_COMPILER_GCC) + static ETL_CONSTANT bool value = __has_trivial_copy(T); +#else + static ETL_CONSTANT bool value = __is_trivially_copyable(T); +#endif }; - //*************************************************************************** + //********************************************* // is_trivially_copyable template - struct is_trivially_copyable : public etl::bool_constant<__is_trivially_copyable(T)> + struct is_trivially_copyable { +#if defined(ETL_COMPILER_GCC) + static ETL_CONSTANT bool value = __has_trivial_copy(T); +#else + static ETL_CONSTANT bool value = __is_trivially_copyable(T); +#endif }; -#elif defined(ETL_USER_DEFINED_TYPE_TRAITS) +#elif defined(ETL_USER_DEFINED_TYPE_TRAITS) && !defined(ETL_USE_TYPE_TRAITS_BUILTINS) //********************************************* // Force the user to provide specialisations for @@ -1726,9 +1791,9 @@ namespace etl //********************************************* // is_assignable template ::value || etl::is_pointer::value) && (etl::is_arithmetic::value || etl::is_pointer::value)> - struct is_assignable; + typename T2, + bool B = (etl::is_arithmetic::value || etl::is_pointer::value) && (etl::is_arithmetic::value || etl::is_pointer::value)> + struct is_assignable; template struct is_assignable : public etl::true_type @@ -1797,7 +1862,7 @@ namespace etl template struct is_trivially_constructible; - //*************************************************************************** + //********************************************* // is_trivially_copy_constructible template ::value || etl::is_pointer::value> struct is_trivially_copy_constructible; @@ -1810,7 +1875,7 @@ namespace etl template struct is_trivially_copy_constructible; - //*************************************************************************** + //********************************************* // is_trivially_destructible template ::value || etl::is_pointer::value> struct is_trivially_destructible; @@ -1823,7 +1888,7 @@ namespace etl template struct is_trivially_destructible; - //*************************************************************************** + //********************************************* // is_trivially_copy_assignable template ::value || etl::is_pointer::value> struct is_trivially_copy_assignable; @@ -1836,7 +1901,7 @@ namespace etl template struct is_trivially_copy_assignable; - //*************************************************************************** + //********************************************* // is_trivially_copyable template ::value || etl::is_pointer::value> struct is_trivially_copyable; @@ -1893,28 +1958,28 @@ namespace etl { }; - //*************************************************************************** + //********************************************* // is_trivially_copy_constructible template struct is_trivially_copy_constructible : public etl::bool_constant::value || etl::is_pointer::value> { }; - //*************************************************************************** + //********************************************* // is_trivially_destructible template struct is_trivially_destructible : public etl::bool_constant::value || etl::is_pointer::value> { }; - //*************************************************************************** + //********************************************* // is_trivially_copy_assignable template struct is_trivially_copy_assignable : public etl::bool_constant::value || etl::is_pointer::value> { }; - //*************************************************************************** + //********************************************* // is_trivially_copyable template struct is_trivially_copyable : public etl::bool_constant::value || etl::is_pointer::value> diff --git a/include/etl/type_traits.h b/include/etl/type_traits.h index a9fad8cf..5ec0db6f 100644 --- a/include/etl/type_traits.h +++ b/include/etl/type_traits.h @@ -488,10 +488,10 @@ namespace etl template <> struct make_unsigned { typedef etl::conditional::type>::type type; + uint16_t, + etl::conditional::type>::type type; }; template <> struct make_unsigned { typedef unsigned int type; }; @@ -1199,7 +1199,7 @@ namespace etl ///\ingroup type_traits template struct alignment_of : std::alignment_of {}; template <> struct alignment_of : std::integral_constant {}; - template <> struct alignment_of : integral_constant {}; + template <> struct alignment_of : std::integral_constant {}; #if ETL_CPP17_SUPPORTED template @@ -1461,8 +1461,8 @@ namespace etl /// conjunction #if ETL_CPP11_SUPPORTED template - struct conjunction : public etl::true_type - { + struct conjunction : public etl::true_type + { }; template @@ -1484,14 +1484,14 @@ namespace etl //*************************************************************************** /// disjunction #if ETL_CPP11_SUPPORTED - template - struct disjunction : public etl::false_type - { + template + struct disjunction : public etl::false_type + { }; template - struct disjunction : public etl::conditional_t> - { + struct disjunction : public etl::conditional_t> + { }; template struct disjunction : public T1 @@ -1640,7 +1640,7 @@ namespace etl #endif #elif defined(ETL_USE_TYPE_TRAITS_BUILTINS) && !defined(ETL_USER_DEFINED_TYPE_TRAITS) - + //********************************************* // Use the compiler's builtins. //********************************************* @@ -1653,7 +1653,7 @@ namespace etl static ETL_CONSTANT bool value = __is_assignable(T1, T2); }; - #if ETL_CPP11_SUPPORTED +#if ETL_CPP11_SUPPORTED //********************************************* // is_constructible template @@ -1661,7 +1661,7 @@ namespace etl { static ETL_CONSTANT bool value = __is_constructible(T, TArgs...); }; - #else +#else //********************************************* // is_constructible template @@ -1677,7 +1677,7 @@ namespace etl { static ETL_CONSTANT bool value = __is_constructible(T); }; - #endif +#endif //********************************************* // is_copy_constructible @@ -1699,11 +1699,11 @@ namespace etl template struct is_trivially_constructible { - #if defined(ETL_COMPILER_GCC) +#if defined(ETL_COMPILER_GCC) static ETL_CONSTANT bool value = __has_trivial_constructor(T); - #else +#else static ETL_CONSTANT bool value = __is_trivially_constructible(T, TArgs...); - #endif +#endif }; #else //********************************************* @@ -1743,11 +1743,11 @@ namespace etl template struct is_trivially_destructible { - #if defined(ETL_COMPILER_GCC) - static ETL_CONSTANT bool value = __has_trivial_destructor(T); - #else - static ETL_CONSTANT bool value = __is_trivially_destructible(T); - #endif +#if defined(ETL_COMPILER_GCC) + static ETL_CONSTANT bool value = __has_trivial_destructor(T); +#else + static ETL_CONSTANT bool value = __is_trivially_destructible(T); +#endif }; //********************************************* @@ -1755,11 +1755,11 @@ namespace etl template struct is_trivially_copy_assignable { - #if defined(ETL_COMPILER_GCC) +#if defined(ETL_COMPILER_GCC) static ETL_CONSTANT bool value = __has_trivial_copy(T); - #else +#else static ETL_CONSTANT bool value = __is_trivially_copyable(T); - #endif +#endif }; //********************************************* @@ -1767,24 +1767,24 @@ namespace etl template struct is_trivially_copyable { - #if defined(ETL_COMPILER_GCC) +#if defined(ETL_COMPILER_GCC) static ETL_CONSTANT bool value = __has_trivial_copy(T); - #else +#else static ETL_CONSTANT bool value = __is_trivially_copyable(T); - #endif +#endif }; #elif defined(ETL_USER_DEFINED_TYPE_TRAITS) && !defined(ETL_USE_TYPE_TRAITS_BUILTINS) - + //********************************************* // Force the user to provide specialisations for // anything other than arithmetics and pointers. //********************************************* - + //********************************************* // is_assignable - template ::value || etl::is_pointer::value) && (etl::is_arithmetic::value || etl::is_pointer::value)> struct is_assignable; @@ -1828,7 +1828,7 @@ namespace etl template struct is_copy_constructible; - + //********************************************* // is_move_constructible template ::value || etl::is_pointer::value> @@ -1921,14 +1921,14 @@ namespace etl { }; - #if ETL_CPP11_SUPPORTED +#if ETL_CPP11_SUPPORTED //********************************************* // is_constructible template struct is_constructible : public etl::bool_constant::value || etl::is_pointer::value> { }; - #endif +#endif //********************************************* // is_copy_constructible