diff --git a/include/etl/deque.h b/include/etl/deque.h index 44043cdc8..097147290 100644 --- a/include/etl/deque.h +++ b/include/etl/deque.h @@ -1758,7 +1758,7 @@ namespace etl void push_back(const_reference item) { ETL_ASSERT_CHECK_PUSH_POP_OR_RETURN(!full(), ETL_ERROR(deque_full)); - + create_element_back(item); } @@ -1771,7 +1771,7 @@ namespace etl void push_back(rvalue_reference item) { ETL_ASSERT_CHECK_PUSH_POP_OR_RETURN(!full(), ETL_ERROR(deque_full)); - + create_element_back(etl::move(item)); } #endif @@ -2484,9 +2484,7 @@ namespace etl void repair() #endif { -#if ETL_CPP11_TYPE_TRAITS_IS_TRIVIAL_SUPPORTED ETL_ASSERT(etl::is_trivially_copyable::value, ETL_ERROR(etl::deque_incompatible_type)); -#endif etl::ideque::repair_buffer(reinterpret_cast(buffer.raw)); } diff --git a/include/etl/generators/type_traits_generator.h b/include/etl/generators/type_traits_generator.h index d47c14dc2..5291506f9 100644 --- a/include/etl/generators/type_traits_generator.h +++ b/include/etl/generators/type_traits_generator.h @@ -742,11 +742,11 @@ namespace etl ///\ingroup type_traits /// Implemented by checking if type is convertible to an integer through static_cast - namespace private_type_traits + namespace private_type_traits { // Base case template - struct is_convertible_to_int + struct is_convertible_to_int : false_type { }; @@ -755,7 +755,7 @@ namespace etl // 2nd template argument of base case defaults to int to ensure that this partial specialization is always tried first template struct is_convertible_to_int(declval()))> - : true_type + : true_type { }; } @@ -765,7 +765,7 @@ namespace etl : integral_constant::value && !is_class::value && !is_arithmetic::value && - !is_reference::value> + !is_reference::value> { }; @@ -1577,7 +1577,7 @@ typedef integral_constant true_type; //*************************************************************************** /// Get the Nth base of a recursively inherited type. /// Requires that the class has defined 'base_type'. - //*************************************************************************** + //*************************************************************************** // Recursive definition of the type. template struct nth_base @@ -1789,190 +1789,30 @@ typedef integral_constant true_type; //********************************************* // is_trivially_constructible -#if ETL_CPP11_TYPE_TRAITS_IS_TRIVIAL_SUPPORTED template using is_trivially_constructible = std::is_trivially_constructible; -#else - template - using is_trivially_constructible = etl::bool_constant::value || etl::is_pointer::value>; -#endif //********************************************* // is_trivially_copy_constructible -#if ETL_CPP11_TYPE_TRAITS_IS_TRIVIAL_SUPPORTED template using is_trivially_copy_constructible = std::is_trivially_copy_constructible; -#else - template - using is_trivially_copy_constructible = etl::bool_constant::value || etl::is_pointer::value>; -#endif //********************************************* // is_trivially_destructible -#if ETL_CPP11_TYPE_TRAITS_IS_TRIVIAL_SUPPORTED template using is_trivially_destructible = std::is_trivially_destructible; -#else - template - using is_trivially_destructible = etl::bool_constant::value || etl::is_pointer::value>; -#endif //********************************************* // is_trivially_copy_assignable -#if ETL_CPP11_TYPE_TRAITS_IS_TRIVIAL_SUPPORTED template using is_trivially_copy_assignable = std::is_trivially_copy_assignable; -#else - template - using is_trivially_copy_assignable = etl::bool_constant::value || etl::is_pointer::value>; -#endif //********************************************* // is_trivially_copyable -#if ETL_CPP11_TYPE_TRAITS_IS_TRIVIAL_SUPPORTED template using is_trivially_copyable = std::is_trivially_copyable; -#else - template - using is_trivially_copyable = etl::bool_constant::value || etl::is_pointer::value>; -#endif - -#elif defined(ETL_USE_TYPE_TRAITS_BUILTINS) && !defined(ETL_USER_DEFINED_TYPE_TRAITS) - - //********************************************* - // Use the compiler's builtins. - //********************************************* - - //********************************************* - // is_assignable - template - struct is_assignable - { - static ETL_CONSTANT bool value = __is_assignable(T1, T2); - }; - -#if ETL_USING_CPP11 - //********************************************* - // is_constructible - template - 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::type> - { - }; - - //********************************************* - // is_move_constructible - template - struct is_move_constructible : public etl::is_constructible - { - }; - -#if ETL_USING_CPP11 - //********************************************* - // 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 - { -#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 is_trivially_constructible::type> - { - }; - - //********************************************* - // is_trivially_destructible - 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 - }; - - //********************************************* - // is_trivially_copy_assignable - template - 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 - { -#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) && !defined(ETL_USE_TYPE_TRAITS_BUILTINS) +#elif defined(ETL_USER_DEFINED_TYPE_TRAITS) //********************************************* // Force the user to provide specialisations for @@ -2108,21 +1948,38 @@ typedef integral_constant true_type; #else //********************************************* - // Assume that anything other than arithmetics - // and pointers return false for the traits. + // Deduce traits based on if builtins exist. //********************************************* //********************************************* // is_assignable +#if ETL_USING_BUILTIN_IS_ASSIGNABLE + template + struct is_assignable + { + static ETL_CONSTANT bool value = __is_assignable(T1, T2); + }; +#else template struct is_assignable : public etl::bool_constant<(etl::is_arithmetic::value || etl::is_pointer::value) && (etl::is_arithmetic::value || etl::is_pointer::value)> { }; +#endif #if ETL_USING_CPP11 +#if ETL_USING_BUILTIN_IS_CONSTRUCTIBLE + //********************************************* + // is_constructible + template + struct is_constructible + { + static ETL_CONSTANT bool value = __is_constructible(T, TArgs...); + }; + +#else //*************************************************************************** - /// is_constructible - namespace private_type_traits + /// is_constructible_ + namespace private_type_traits { template struct is_constructible_ : etl::false_type {}; @@ -2135,6 +1992,7 @@ typedef integral_constant true_type; // is_constructible template using is_constructible = private_type_traits::is_constructible_, T, Args...>; +#endif //********************************************* // is_copy_constructible @@ -2153,7 +2011,31 @@ typedef integral_constant true_type; template <> struct is_move_constructible : public false_type{}; #else +#if ETL_USING_BUILTIN_IS_CONSTRUCTIBLE + //********************************************* + // 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); + }; + //********************************************* + // is_copy_constructible + template struct is_copy_constructible : public is_constructible::type>::type>{}; + + //********************************************* + // is_move_constructible + template struct is_move_constructible : public is_constructible{}; +#else //********************************************* // is_copy_constructible template @@ -2168,7 +2050,53 @@ typedef integral_constant true_type; { }; #endif +#endif + +#if ETL_USING_BUILTIN_IS_TRIVIALLY_CONSTRUCTIBLE +#if ETL_USING_CPP11 + //********************************************* + // 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 + { +#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 is_trivially_constructible::type> + { + }; +#else //********************************************* // is_trivially_constructible template @@ -2182,28 +2110,70 @@ typedef integral_constant true_type; struct is_trivially_copy_constructible : public etl::bool_constant::value || etl::is_pointer::value> { }; +#endif +#if ETL_USING_BUILTIN_IS_TRIVIALLY_DESTRUCTIBLE + //********************************************* + // is_trivially_destructible + 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 + }; +#else //********************************************* // is_trivially_destructible template struct is_trivially_destructible : public etl::bool_constant::value || etl::is_pointer::value> { }; +#endif +#if ETL_USING_BUILTIN_IS_TRIVIALLY_ASSIGNABLE + //********************************************* + // is_trivially_copy_assignable + template + struct is_trivially_copy_assignable + { +#if defined(ETL_COMPILER_GCC) + static ETL_CONSTANT bool value = __has_trivial_assign(T); +#else + static ETL_CONSTANT bool value = __is_trivially_assignable(typename add_lvalue_reference::type, + typename add_lvalue_reference::type); +#endif + }; +#else //********************************************* // is_trivially_copy_assignable template struct is_trivially_copy_assignable : public etl::bool_constant::value || etl::is_pointer::value> { }; +#endif +#if ETL_USING_BUILTIN_IS_TRIVIALLY_COPYABLE + //********************************************* + // is_trivially_copyable + template + 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 + }; +#else //********************************************* // is_trivially_copyable template struct is_trivially_copyable : public etl::bool_constant::value || etl::is_pointer::value> { }; - #endif template @@ -2238,8 +2208,8 @@ typedef integral_constant true_type; template inline constexpr bool is_constructible_v = etl::is_constructible::value; - template - inline constexpr bool is_default_constructible_v = etl::is_default_constructible::value; + template + inline constexpr bool is_default_constructible_v = etl::is_default_constructible::value; template inline constexpr bool is_copy_constructible_v = etl::is_copy_constructible::value; @@ -2247,8 +2217,8 @@ typedef integral_constant true_type; template inline constexpr bool is_move_constructible_v = etl::is_move_constructible::value; - template - inline constexpr bool is_trivially_constructible_v = etl::is_trivially_constructible::value; + template + inline constexpr bool is_trivially_constructible_v = etl::is_trivially_constructible::value; template inline constexpr bool is_trivially_copy_constructible_v = etl::is_trivially_copy_constructible::value; @@ -2263,6 +2233,7 @@ typedef integral_constant true_type; inline constexpr bool is_trivially_copyable_v = etl::is_trivially_copyable::value; #endif +#endif // ETL_USING_STL && ETL_USING_CPP11 && !defined(ETL_USE_TYPE_TRAITS_BUILTINS) && !defined(ETL_USER_DEFINED_TYPE_TRAITS) #if ETL_USING_CPP11 //********************************************* @@ -2301,7 +2272,7 @@ typedef integral_constant true_type; }; template - struct common_type_2_impl + struct common_type_2_impl : decay_conditional_result { }; @@ -2319,8 +2290,8 @@ typedef integral_constant true_type; struct common_type : etl::conditional::type>::value&& etl::is_same::type>::value, private_common_type::common_type_2_impl, - common_type::type, - typename etl::decay::type>>::type + common_type::type, + typename etl::decay::type>>::type { }; @@ -2489,6 +2460,28 @@ typedef integral_constant true_type; template class Template> inline constexpr bool is_specialization_v = etl::is_specialization::value; #endif + + //********************************************* + // is_constant_evaluated + ETL_CONSTEXPR inline bool is_constant_evaluated() ETL_NOEXCEPT + { +#if ETL_USING_CPP23 + if consteval + { + return true; + } + else + { + return false; + } +#elif ETL_USING_BUILTIN_IS_CONSTANT_EVALUATED == 1 + // fallback for C++20 on supported compilers + return __builtin_is_constant_evaluated(); +#else + // default if unsupported + return false; +#endif + } } // Helper macros diff --git a/include/etl/profiles/arduino_arm.h b/include/etl/profiles/arduino_arm.h index 626d2ebf1..f61cc1e03 100644 --- a/include/etl/profiles/arduino_arm.h +++ b/include/etl/profiles/arduino_arm.h @@ -43,6 +43,5 @@ SOFTWARE. #define ETL_CPP17_SUPPORTED 0 #define ETL_NO_NULLPTR_SUPPORT 1 #define ETL_NO_LARGE_CHAR_SUPPORT 1 -#define ETL_CPP11_TYPE_TRAITS_IS_TRIVIAL_SUPPORTED 0 #endif diff --git a/include/etl/profiles/armv5.h b/include/etl/profiles/armv5.h index e1811d543..05745792d 100644 --- a/include/etl/profiles/armv5.h +++ b/include/etl/profiles/armv5.h @@ -43,6 +43,5 @@ SOFTWARE. #define ETL_CPP17_SUPPORTED 0 #define ETL_NO_NULLPTR_SUPPORT (__cplusplus < 201103L) #define ETL_NO_LARGE_CHAR_SUPPORT (__cplusplus < 201103L) -#define ETL_CPP11_TYPE_TRAITS_IS_TRIVIAL_SUPPORTED 0 #endif diff --git a/include/etl/profiles/armv5_no_stl.h b/include/etl/profiles/armv5_no_stl.h index 97583e3fe..6215f1cb7 100644 --- a/include/etl/profiles/armv5_no_stl.h +++ b/include/etl/profiles/armv5_no_stl.h @@ -43,7 +43,6 @@ SOFTWARE. #define ETL_CPP17_SUPPORTED 0 #define ETL_NO_NULLPTR_SUPPORT (__cplusplus < 201103L) #define ETL_NO_LARGE_CHAR_SUPPORT (__cplusplus < 201103L) -#define ETL_CPP11_TYPE_TRAITS_IS_TRIVIAL_SUPPORTED 0 #define ETL_NO_STL #endif diff --git a/include/etl/profiles/armv6.h b/include/etl/profiles/armv6.h index 93e9e8764..a4d824fe2 100644 --- a/include/etl/profiles/armv6.h +++ b/include/etl/profiles/armv6.h @@ -43,6 +43,5 @@ SOFTWARE. #define ETL_CPP17_SUPPORTED 0 #define ETL_NO_NULLPTR_SUPPORT 0 #define ETL_NO_LARGE_CHAR_SUPPORT 0 -#define ETL_CPP11_TYPE_TRAITS_IS_TRIVIAL_SUPPORTED 1 #endif diff --git a/include/etl/profiles/armv6_no_stl.h b/include/etl/profiles/armv6_no_stl.h index cd0d103dc..4fdfc3c40 100644 --- a/include/etl/profiles/armv6_no_stl.h +++ b/include/etl/profiles/armv6_no_stl.h @@ -43,7 +43,6 @@ SOFTWARE. #define ETL_CPP17_SUPPORTED 0 #define ETL_NO_NULLPTR_SUPPORT 0 #define ETL_NO_LARGE_CHAR_SUPPORT 0 -#define ETL_CPP11_TYPE_TRAITS_IS_TRIVIAL_SUPPORTED 1 #define ETL_NO_STL #endif diff --git a/include/etl/profiles/armv7.h b/include/etl/profiles/armv7.h index 05ff49656..f09f20de7 100644 --- a/include/etl/profiles/armv7.h +++ b/include/etl/profiles/armv7.h @@ -43,6 +43,5 @@ SOFTWARE. #define ETL_CPP17_SUPPORTED 0 #define ETL_NO_NULLPTR_SUPPORT 0 #define ETL_NO_LARGE_CHAR_SUPPORT 0 -#define ETL_CPP11_TYPE_TRAITS_IS_TRIVIAL_SUPPORTED 1 #endif diff --git a/include/etl/profiles/armv7_no_stl.h b/include/etl/profiles/armv7_no_stl.h index 1c177300b..8054e85ed 100644 --- a/include/etl/profiles/armv7_no_stl.h +++ b/include/etl/profiles/armv7_no_stl.h @@ -43,7 +43,6 @@ SOFTWARE. #define ETL_CPP17_SUPPORTED 0 #define ETL_NO_NULLPTR_SUPPORT 0 #define ETL_NO_LARGE_CHAR_SUPPORT 0 -#define ETL_CPP11_TYPE_TRAITS_IS_TRIVIAL_SUPPORTED 1 #define ETL_NO_STL #endif diff --git a/include/etl/profiles/cpp03.h b/include/etl/profiles/cpp03.h index 57e8c6358..781c498b3 100644 --- a/include/etl/profiles/cpp03.h +++ b/include/etl/profiles/cpp03.h @@ -43,6 +43,5 @@ SOFTWARE. #define ETL_CPP17_SUPPORTED 0 #define ETL_NO_NULLPTR_SUPPORT 1 #define ETL_NO_LARGE_CHAR_SUPPORT 1 -#define ETL_CPP11_TYPE_TRAITS_IS_TRIVIAL_SUPPORTED 0 #endif diff --git a/include/etl/profiles/cpp03_no_stl.h b/include/etl/profiles/cpp03_no_stl.h index fba6a267c..8ff7533c6 100644 --- a/include/etl/profiles/cpp03_no_stl.h +++ b/include/etl/profiles/cpp03_no_stl.h @@ -43,7 +43,6 @@ SOFTWARE. #define ETL_CPP17_SUPPORTED 0 #define ETL_NO_NULLPTR_SUPPORT 1 #define ETL_NO_LARGE_CHAR_SUPPORT 1 -#define ETL_CPP11_TYPE_TRAITS_IS_TRIVIAL_SUPPORTED 0 #define ETL_NO_STL #endif diff --git a/include/etl/profiles/cpp11.h b/include/etl/profiles/cpp11.h index ad17f37b2..47bae7610 100644 --- a/include/etl/profiles/cpp11.h +++ b/include/etl/profiles/cpp11.h @@ -43,6 +43,5 @@ SOFTWARE. #define ETL_CPP17_SUPPORTED 0 #define ETL_NO_NULLPTR_SUPPORT 0 #define ETL_NO_LARGE_CHAR_SUPPORT 0 -#define ETL_CPP11_TYPE_TRAITS_IS_TRIVIAL_SUPPORTED 1 #endif diff --git a/include/etl/profiles/cpp11_no_stl.h b/include/etl/profiles/cpp11_no_stl.h index 5482cff96..319249ff1 100644 --- a/include/etl/profiles/cpp11_no_stl.h +++ b/include/etl/profiles/cpp11_no_stl.h @@ -43,7 +43,6 @@ SOFTWARE. #define ETL_CPP17_SUPPORTED 0 #define ETL_NO_NULLPTR_SUPPORT 0 #define ETL_NO_LARGE_CHAR_SUPPORT 0 -#define ETL_CPP11_TYPE_TRAITS_IS_TRIVIAL_SUPPORTED 0 #define ETL_NO_STL #endif diff --git a/include/etl/profiles/cpp14.h b/include/etl/profiles/cpp14.h index 4c2e3d2d4..c743b6f2e 100644 --- a/include/etl/profiles/cpp14.h +++ b/include/etl/profiles/cpp14.h @@ -43,6 +43,5 @@ SOFTWARE. #define ETL_CPP17_SUPPORTED 0 #define ETL_NO_NULLPTR_SUPPORT 0 #define ETL_NO_LARGE_CHAR_SUPPORT 0 -#define ETL_CPP11_TYPE_TRAITS_IS_TRIVIAL_SUPPORTED 1 #endif diff --git a/include/etl/profiles/cpp14_no_stl.h b/include/etl/profiles/cpp14_no_stl.h index 4e08450ec..7c6885091 100644 --- a/include/etl/profiles/cpp14_no_stl.h +++ b/include/etl/profiles/cpp14_no_stl.h @@ -43,7 +43,6 @@ SOFTWARE. #define ETL_CPP17_SUPPORTED 0 #define ETL_NO_NULLPTR_SUPPORT 0 #define ETL_NO_LARGE_CHAR_SUPPORT 0 -#define ETL_CPP11_TYPE_TRAITS_IS_TRIVIAL_SUPPORTED 0 #define ETL_NO_STL #endif diff --git a/include/etl/profiles/cpp17.h b/include/etl/profiles/cpp17.h index 69aed5093..4ad6d89bc 100644 --- a/include/etl/profiles/cpp17.h +++ b/include/etl/profiles/cpp17.h @@ -43,6 +43,5 @@ SOFTWARE. #define ETL_CPP17_SUPPORTED 1 #define ETL_NO_NULLPTR_SUPPORT 0 #define ETL_NO_LARGE_CHAR_SUPPORT 0 -#define ETL_CPP11_TYPE_TRAITS_IS_TRIVIAL_SUPPORTED 1 #endif diff --git a/include/etl/profiles/cpp17_no_stl.h b/include/etl/profiles/cpp17_no_stl.h index 5bac2b398..5d098ba46 100644 --- a/include/etl/profiles/cpp17_no_stl.h +++ b/include/etl/profiles/cpp17_no_stl.h @@ -43,7 +43,6 @@ SOFTWARE. #define ETL_CPP17_SUPPORTED 1 #define ETL_NO_NULLPTR_SUPPORT 0 #define ETL_NO_LARGE_CHAR_SUPPORT 0 -#define ETL_CPP11_TYPE_TRAITS_IS_TRIVIAL_SUPPORTED 0 #define ETL_NO_STL #endif diff --git a/include/etl/profiles/determine_builtin_support.h b/include/etl/profiles/determine_builtin_support.h index b45b23f7c..bde5e1106 100644 --- a/include/etl/profiles/determine_builtin_support.h +++ b/include/etl/profiles/determine_builtin_support.h @@ -48,6 +48,10 @@ SOFTWARE. #define ETL_USING_BUILTIN_IS_TRIVIALLY_DESTRUCTIBLE 1 #endif + #if !defined(ETL_USING_BUILTIN_IS_TRIVIALLY_ASSIGNABLE) + #define ETL_USING_BUILTIN_IS_TRIVIALLY_ASSIGNABLE 1 + #endif + #if !defined(ETL_USING_BUILTIN_IS_TRIVIALLY_COPYABLE) #define ETL_USING_BUILTIN_IS_TRIVIALLY_COPYABLE 1 #endif @@ -98,6 +102,10 @@ SOFTWARE. #define ETL_USING_BUILTIN_IS_TRIVIALLY_DESTRUCTIBLE (__has_builtin(__has_trivial_destructor) || __has_builtin(__is_trivially_destructible)) #endif + #if !defined(ETL_USING_BUILTIN_IS_TRIVIALLY_ASSIGNABLE) + #define ETL_USING_BUILTIN_IS_TRIVIALLY_ASSIGNABLE (__has_builtin(__has_trivial_assign) || __has_builtin(__is_trivially_assignable)) + #endif + #if !defined(ETL_USING_BUILTIN_IS_TRIVIALLY_COPYABLE) #define ETL_USING_BUILTIN_IS_TRIVIALLY_COPYABLE (__has_builtin(__has_trivial_copy) || __has_builtin(__is_trivially_copyable)) #endif @@ -148,6 +156,10 @@ SOFTWARE. #define ETL_USING_BUILTIN_IS_TRIVIALLY_DESTRUCTIBLE 0 #endif +#if !defined(ETL_USING_BUILTIN_IS_TRIVIALLY_ASSIGNABLE) + #define ETL_USING_BUILTIN_IS_TRIVIALLY_ASSIGNABLE 0 +#endif + #if !defined(ETL_USING_BUILTIN_IS_TRIVIALLY_COPYABLE) #define ETL_USING_BUILTIN_IS_TRIVIALLY_COPYABLE 0 #endif @@ -190,6 +202,7 @@ namespace etl static ETL_CONSTANT bool using_builtin_is_constructible = (ETL_USING_BUILTIN_IS_CONSTRUCTIBLE == 1); static ETL_CONSTANT bool using_builtin_is_trivially_constructible = (ETL_USING_BUILTIN_IS_TRIVIALLY_CONSTRUCTIBLE == 1); static ETL_CONSTANT bool using_builtin_is_trivially_destructible = (ETL_USING_BUILTIN_IS_TRIVIALLY_DESTRUCTIBLE == 1); + static ETL_CONSTANT bool using_builtin_is_trivially_assignable = (ETL_USING_BUILTIN_IS_TRIVIALLY_ASSIGNABLE == 1); static ETL_CONSTANT bool using_builtin_is_trivially_copyable = (ETL_USING_BUILTIN_IS_TRIVIALLY_COPYABLE == 1); static ETL_CONSTANT bool using_builtin_underlying_type = (ETL_USING_BUILTIN_UNDERLYING_TYPE == 1); static ETL_CONSTANT bool using_builtin_is_constant_evaluated = (ETL_USING_BUILTIN_IS_CONSTANT_EVALUATED == 1); diff --git a/include/etl/profiles/determine_compiler_language_support.h b/include/etl/profiles/determine_compiler_language_support.h index 322cee871..9b24090a7 100644 --- a/include/etl/profiles/determine_compiler_language_support.h +++ b/include/etl/profiles/determine_compiler_language_support.h @@ -192,10 +192,6 @@ SOFTWARE. #define ETL_NO_LARGE_CHAR_SUPPORT ETL_NOT_USING_CPP11 #endif -#if !defined(ETL_CPP11_TYPE_TRAITS_IS_TRIVIAL_SUPPORTED) - #define ETL_CPP11_TYPE_TRAITS_IS_TRIVIAL_SUPPORTED ETL_USING_CPP11 -#endif - // Language standard #if !defined(ETL_LANGUAGE_STANDARD) #if ETL_USING_CPP23 diff --git a/include/etl/profiles/segger_gcc_stlport.h b/include/etl/profiles/segger_gcc_stlport.h index 74fc10d8b..7e5833b6c 100644 --- a/include/etl/profiles/segger_gcc_stlport.h +++ b/include/etl/profiles/segger_gcc_stlport.h @@ -48,7 +48,6 @@ SOFTWARE. #endif #define ETL_NO_NULLPTR_SUPPORT 1 #define ETL_NO_LARGE_CHAR_SUPPORT ETL_CPP11_NOT_SUPPORTED -#define ETL_CPP11_TYPE_TRAITS_IS_TRIVIAL_SUPPORTED 0 #define ETL_STLPORT 1 #endif diff --git a/include/etl/profiles/ticc.h b/include/etl/profiles/ticc.h index 50aa64461..8cf0ff401 100644 --- a/include/etl/profiles/ticc.h +++ b/include/etl/profiles/ticc.h @@ -42,6 +42,5 @@ SOFTWARE. #define ETL_CPP17_SUPPORTED 0 #define ETL_NO_NULLPTR_SUPPORT 1 #define ETL_NO_LARGE_CHAR_SUPPORT 1 -#define ETL_CPP11_TYPE_TRAITS_IS_TRIVIAL_SUPPORTED 0 #endif diff --git a/include/etl/profiles/ticc_no_stl.h b/include/etl/profiles/ticc_no_stl.h index e0b2c20c6..e0c502487 100644 --- a/include/etl/profiles/ticc_no_stl.h +++ b/include/etl/profiles/ticc_no_stl.h @@ -42,7 +42,6 @@ SOFTWARE. #define ETL_CPP17_SUPPORTED 0 #define ETL_NO_NULLPTR_SUPPORT 1 #define ETL_NO_LARGE_CHAR_SUPPORT 1 -#define ETL_CPP11_TYPE_TRAITS_IS_TRIVIAL_SUPPORTED 0 #define ETL_NO_STL #endif diff --git a/include/etl/type_traits.h b/include/etl/type_traits.h index 3c9ac66b7..f95c8c127 100644 --- a/include/etl/type_traits.h +++ b/include/etl/type_traits.h @@ -730,11 +730,11 @@ namespace etl ///\ingroup type_traits /// Implemented by checking if type is convertible to an integer through static_cast - namespace private_type_traits + namespace private_type_traits { // Base case template - struct is_convertible_to_int + struct is_convertible_to_int : false_type { }; @@ -743,7 +743,7 @@ namespace etl // 2nd template argument of base case defaults to int to ensure that this partial specialization is always tried first template struct is_convertible_to_int(declval()))> - : true_type + : true_type { }; } @@ -753,7 +753,7 @@ namespace etl : integral_constant::value && !is_class::value && !is_arithmetic::value && - !is_reference::value> + !is_reference::value> { }; @@ -1570,7 +1570,7 @@ typedef integral_constant true_type; //*************************************************************************** /// Get the Nth base of a recursively inherited type. /// Requires that the class has defined 'base_type'. - //*************************************************************************** + //*************************************************************************** // Recursive definition of the type. template struct nth_base @@ -1782,190 +1782,30 @@ typedef integral_constant true_type; //********************************************* // is_trivially_constructible -#if ETL_CPP11_TYPE_TRAITS_IS_TRIVIAL_SUPPORTED template using is_trivially_constructible = std::is_trivially_constructible; -#else - template - using is_trivially_constructible = etl::bool_constant::value || etl::is_pointer::value>; -#endif //********************************************* // is_trivially_copy_constructible -#if ETL_CPP11_TYPE_TRAITS_IS_TRIVIAL_SUPPORTED template using is_trivially_copy_constructible = std::is_trivially_copy_constructible; -#else - template - using is_trivially_copy_constructible = etl::bool_constant::value || etl::is_pointer::value>; -#endif //********************************************* // is_trivially_destructible -#if ETL_CPP11_TYPE_TRAITS_IS_TRIVIAL_SUPPORTED template using is_trivially_destructible = std::is_trivially_destructible; -#else - template - using is_trivially_destructible = etl::bool_constant::value || etl::is_pointer::value>; -#endif //********************************************* // is_trivially_copy_assignable -#if ETL_CPP11_TYPE_TRAITS_IS_TRIVIAL_SUPPORTED template using is_trivially_copy_assignable = std::is_trivially_copy_assignable; -#else - template - using is_trivially_copy_assignable = etl::bool_constant::value || etl::is_pointer::value>; -#endif //********************************************* // is_trivially_copyable -#if ETL_CPP11_TYPE_TRAITS_IS_TRIVIAL_SUPPORTED template using is_trivially_copyable = std::is_trivially_copyable; -#else - template - using is_trivially_copyable = etl::bool_constant::value || etl::is_pointer::value>; -#endif - -#elif defined(ETL_USE_TYPE_TRAITS_BUILTINS) && !defined(ETL_USER_DEFINED_TYPE_TRAITS) - - //********************************************* - // Use the compiler's builtins. - //********************************************* - - //********************************************* - // is_assignable - template - struct is_assignable - { - static ETL_CONSTANT bool value = __is_assignable(T1, T2); - }; - -#if ETL_USING_CPP11 - //********************************************* - // is_constructible - template - 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::type> - { - }; - - //********************************************* - // is_move_constructible - template - struct is_move_constructible : public etl::is_constructible - { - }; - -#if ETL_USING_CPP11 - //********************************************* - // 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 - { -#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 is_trivially_constructible::type> - { - }; - - //********************************************* - // is_trivially_destructible - 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 - }; - - //********************************************* - // is_trivially_copy_assignable - template - 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 - { -#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) && !defined(ETL_USE_TYPE_TRAITS_BUILTINS) +#elif defined(ETL_USER_DEFINED_TYPE_TRAITS) //********************************************* // Force the user to provide specialisations for @@ -2101,21 +1941,38 @@ typedef integral_constant true_type; #else //********************************************* - // Assume that anything other than arithmetics - // and pointers return false for the traits. + // Deduce traits based on if builtins exist. //********************************************* //********************************************* // is_assignable +#if ETL_USING_BUILTIN_IS_ASSIGNABLE + template + struct is_assignable + { + static ETL_CONSTANT bool value = __is_assignable(T1, T2); + }; +#else template struct is_assignable : public etl::bool_constant<(etl::is_arithmetic::value || etl::is_pointer::value) && (etl::is_arithmetic::value || etl::is_pointer::value)> { }; +#endif #if ETL_USING_CPP11 +#if ETL_USING_BUILTIN_IS_CONSTRUCTIBLE + //********************************************* + // is_constructible + template + struct is_constructible + { + static ETL_CONSTANT bool value = __is_constructible(T, TArgs...); + }; + +#else //*************************************************************************** - /// is_constructible - namespace private_type_traits + /// is_constructible_ + namespace private_type_traits { template struct is_constructible_ : etl::false_type {}; @@ -2128,6 +1985,7 @@ typedef integral_constant true_type; // is_constructible template using is_constructible = private_type_traits::is_constructible_, T, Args...>; +#endif //********************************************* // is_copy_constructible @@ -2146,7 +2004,31 @@ typedef integral_constant true_type; template <> struct is_move_constructible : public false_type{}; #else +#if ETL_USING_BUILTIN_IS_CONSTRUCTIBLE + //********************************************* + // 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); + }; + //********************************************* + // is_copy_constructible + template struct is_copy_constructible : public is_constructible::type>::type>{}; + + //********************************************* + // is_move_constructible + template struct is_move_constructible : public is_constructible{}; +#else //********************************************* // is_copy_constructible template @@ -2161,7 +2043,53 @@ typedef integral_constant true_type; { }; #endif +#endif + +#if ETL_USING_BUILTIN_IS_TRIVIALLY_CONSTRUCTIBLE +#if ETL_USING_CPP11 + //********************************************* + // 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 + { +#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 is_trivially_constructible::type> + { + }; +#else //********************************************* // is_trivially_constructible template @@ -2175,28 +2103,70 @@ typedef integral_constant true_type; struct is_trivially_copy_constructible : public etl::bool_constant::value || etl::is_pointer::value> { }; +#endif +#if ETL_USING_BUILTIN_IS_TRIVIALLY_DESTRUCTIBLE + //********************************************* + // is_trivially_destructible + 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 + }; +#else //********************************************* // is_trivially_destructible template struct is_trivially_destructible : public etl::bool_constant::value || etl::is_pointer::value> { }; +#endif +#if ETL_USING_BUILTIN_IS_TRIVIALLY_ASSIGNABLE + //********************************************* + // is_trivially_copy_assignable + template + struct is_trivially_copy_assignable + { +#if defined(ETL_COMPILER_GCC) + static ETL_CONSTANT bool value = __has_trivial_assign(T); +#else + static ETL_CONSTANT bool value = __is_trivially_assignable(typename add_lvalue_reference::type, + typename add_lvalue_reference::type); +#endif + }; +#else //********************************************* // is_trivially_copy_assignable template struct is_trivially_copy_assignable : public etl::bool_constant::value || etl::is_pointer::value> { }; +#endif +#if ETL_USING_BUILTIN_IS_TRIVIALLY_COPYABLE + //********************************************* + // is_trivially_copyable + template + 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 + }; +#else //********************************************* // is_trivially_copyable template struct is_trivially_copyable : public etl::bool_constant::value || etl::is_pointer::value> { }; - #endif template @@ -2231,8 +2201,8 @@ typedef integral_constant true_type; template inline constexpr bool is_constructible_v = etl::is_constructible::value; - template - inline constexpr bool is_default_constructible_v = etl::is_default_constructible::value; + template + inline constexpr bool is_default_constructible_v = etl::is_default_constructible::value; template inline constexpr bool is_copy_constructible_v = etl::is_copy_constructible::value; @@ -2240,8 +2210,8 @@ typedef integral_constant true_type; template inline constexpr bool is_move_constructible_v = etl::is_move_constructible::value; - template - inline constexpr bool is_trivially_constructible_v = etl::is_trivially_constructible::value; + template + inline constexpr bool is_trivially_constructible_v = etl::is_trivially_constructible::value; template inline constexpr bool is_trivially_copy_constructible_v = etl::is_trivially_copy_constructible::value; @@ -2256,6 +2226,7 @@ typedef integral_constant true_type; inline constexpr bool is_trivially_copyable_v = etl::is_trivially_copyable::value; #endif +#endif // ETL_USING_STL && ETL_USING_CPP11 && !defined(ETL_USE_TYPE_TRAITS_BUILTINS) && !defined(ETL_USER_DEFINED_TYPE_TRAITS) #if ETL_USING_CPP11 //********************************************* @@ -2294,7 +2265,7 @@ typedef integral_constant true_type; }; template - struct common_type_2_impl + struct common_type_2_impl : decay_conditional_result { }; @@ -2312,8 +2283,8 @@ typedef integral_constant true_type; struct common_type : etl::conditional::type>::value&& etl::is_same::type>::value, private_common_type::common_type_2_impl, - common_type::type, - typename etl::decay::type>>::type + common_type::type, + typename etl::decay::type>>::type { };