From 34abed35b062a63c24f86e9c536203b69fbc2241 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Tue, 2 Dec 2025 17:13:10 +0000 Subject: [PATCH] Synchronised generators with source files --- include/etl/fsm.h | 2 +- .../etl/generators/type_traits_generator.h | 274 +++++++++++++++++- include/etl/type_traits.h | 274 +++++++++++++++++- test/vs2022/etl.vcxproj | 54 ++-- 4 files changed, 573 insertions(+), 31 deletions(-) diff --git a/include/etl/fsm.h b/include/etl/fsm.h index 4eaa016a..36130a47 100644 --- a/include/etl/fsm.h +++ b/include/etl/fsm.h @@ -221,7 +221,7 @@ namespace etl struct check_ids : etl::integral_constant::value> { - }; + }; //*************************************************************************** /// RAII detection mechanism to catch reentrant calls to methods that might diff --git a/include/etl/generators/type_traits_generator.h b/include/etl/generators/type_traits_generator.h index a03242a9..8d4753e6 100644 --- a/include/etl/generators/type_traits_generator.h +++ b/include/etl/generators/type_traits_generator.h @@ -800,6 +800,7 @@ namespace etl //*************************************************************************** /// is_convertible + ///\ingroup type_traits #if ETL_USING_CPP11 namespace private_type_traits { @@ -828,11 +829,34 @@ namespace etl decltype(private_type_traits::nonvoid_convertible(0))::value) || (etl::is_void::value && etl::is_void::value)> {}; #endif + + // Is convertible and the conversion is noexcept. + template + struct is_nothrow_convertible + { + private: + // Helper: a function taking TTo to require the conversion. + static void sink(TTo) noexcept; + + // Selected only if 'sink(declval())' is a valid expression. + template + static auto test(int) -> etl::bool_constant()))>; + + // Fallback if conversion is not viable. + template + static etl::false_type test(...); + + public: + static ETL_CONSTANT bool value = decltype(test(0))::value; + }; #endif #if ETL_USING_CPP17 template inline constexpr bool is_convertible_v = etl::is_convertible::value; + + template + inline constexpr bool is_nothrow_convertible_v = etl::is_nothrow_convertible::value; #endif //*************************************************************************** @@ -1353,11 +1377,34 @@ typedef integral_constant true_type; #if ETL_USING_CPP11 template struct is_convertible : std::is_convertible {}; + + // Is convertible and the conversion is noexcept. + template + struct is_nothrow_convertible + { + private: + // Helper: a function taking TTo to require the conversion. + static void sink(TTo) noexcept; + + // Selected only if 'sink(declval())' is a valid expression. + template + static auto test(int) -> etl::bool_constant()))>; + + // Fallback if conversion is not viable. + template + static etl::false_type test(...); + + public: + static ETL_CONSTANT bool value = decltype(test(0))::value; + }; #endif #if ETL_USING_CPP17 template inline constexpr bool is_convertible_v = std::is_convertible_v; + + template + inline constexpr bool is_nothrow_convertible_v = is_nothrow_convertible::value; #endif //*************************************************************************** @@ -2124,17 +2171,17 @@ typedef integral_constant true_type; /// is_constructible namespace private_type_traits { - template + template struct is_constructible_ : etl::false_type {}; - template - struct is_constructible_()...))>, T, Args...> : etl::true_type {}; + template + struct is_constructible_()...))>, T, TArgs...> : etl::true_type {}; } //********************************************* // is_constructible - template - using is_constructible = private_type_traits::is_constructible_, T, Args...>; + template + using is_constructible = private_type_traits::is_constructible_, T, TArgs...>; //********************************************* // is_copy_constructible @@ -2504,13 +2551,228 @@ typedef integral_constant true_type; return false; } #elif ETL_USING_BUILTIN_IS_CONSTANT_EVALUATED == 1 - // fallback for C++20 on supported compilers + // Fallback for C++20 on supported compilers return __builtin_is_constant_evaluated(); #else // default if unsupported return false; #endif } + +#if ETL_USING_CPP11 + //********************************* + /// Check if T is a function type + //********************************* + template + struct is_function : etl::false_type + { + }; + + // Plain / cv-qualified + template + struct is_function : etl::true_type {}; + template + struct is_function : etl::true_type {}; + template + struct is_function : etl::true_type {}; + template + struct is_function : etl::true_type {}; + + // Variadic + template + struct is_function : etl::true_type {}; + + // noexcept variants (if supported by the toolchain) +#if ETL_HAS_NOEXCEPT_FUNCTION_TYPE + template + struct is_function : etl::true_type {}; + template + struct is_function : etl::true_type {}; + template + struct is_function : etl::true_type {}; + template + struct is_function : etl::true_type {}; + template + struct is_function : etl::true_type {}; +#endif + +#if ETL_USING_CPP17 + template + inline constexpr bool is_function_v = etl::is_function::value; +#endif +#endif + +#if ETL_USING_CPP11 + //********************************* + /// Check for the presence of operator() + //********************************* + template >::value, int> = 0> + struct has_call_operator + { + template + static auto test(int) -> decltype(&U::operator(), etl::true_type()); + + template + static etl::false_type test(...); + + static const bool value = etl::is_same(0)), etl::true_type>::value; + }; + +#if ETL_USING_CPP17 + template + inline constexpr bool has_call_operator_v = etl::has_call_operator::value; +#endif +#endif + +#if ETL_USING_CPP11 + //*************************************************************************** + /// Check that there is only one operator() + //*************************************************************************** + template >::value, int> = 0> + struct has_unique_call_operator + { + //********************************* + // Test for presence of operator() + //********************************* + template + static auto test(int) -> decltype(&U::operator(), etl::true_type()); + + //********************************* + // Fallback + //********************************* + template + static auto test(...) -> etl::false_type; + + //********************************* + // true if operator() exists and is unique + //********************************* + static const bool value = decltype(test>(0))::value; + }; + +#if ETL_USING_CPP17 + template + inline constexpr bool has_unique_call_operator_v = etl::has_unique_call_operator::value; +#endif +#endif + + //*************************************************************************** + /// Is T a member pointer + //*************************************************************************** + namespace private_type_traits + { + template + struct is_member_pointer_helper : etl::false_type {}; + + template + struct is_member_pointer_helper : etl::true_type {}; + } + + template + struct is_member_pointer : private_type_traits::is_member_pointer_helper> {}; + +#if ETL_USING_CPP17 + template + inline constexpr bool is_member_pointer_v = etl::is_member_pointer::value; +#endif + + //*************************************************************************** + /// Is T a member function pointer + //*************************************************************************** + template struct is_member_function_pointer : etl::false_type {}; + + template struct is_member_function_pointer : etl::true_type {}; + template struct is_member_function_pointer : etl::true_type {}; + template struct is_member_function_pointer : etl::true_type {}; + template struct is_member_function_pointer : etl::true_type {}; + +#if ETL_HAS_NOEXCEPT_FUNCTION_TYPE + template struct is_member_function_pointer : etl::true_type {}; + template struct is_member_function_pointer : etl::true_type {}; + template struct is_member_function_pointer : etl::true_type {}; + template struct is_member_function_pointer : etl::true_type {}; +#endif + + template struct is_member_function_pointer : etl::true_type {}; + template struct is_member_function_pointer : etl::true_type {}; + template struct is_member_function_pointer : etl::true_type {}; + template struct is_member_function_pointer : etl::true_type {}; + + template struct is_member_function_pointer : etl::true_type {}; + template struct is_member_function_pointer : etl::true_type {}; + template struct is_member_function_pointer : etl::true_type {}; + template struct is_member_function_pointer: etl::true_type {}; + +#if ETL_HAS_NOEXCEPT_FUNCTION_TYPE + template struct is_member_function_pointer : etl::true_type {}; + template struct is_member_function_pointer : etl::true_type {}; + template struct is_member_function_pointer : etl::true_type {}; + template struct is_member_function_pointer : etl::true_type {}; + + template struct is_member_function_pointer : etl::true_type {}; + template struct is_member_function_pointer : etl::true_type {}; + template struct is_member_function_pointer : etl::true_type {}; + template struct is_member_function_pointer: etl::true_type {}; +#endif + + template struct is_member_function_pointer : etl::true_type {}; + template struct is_member_function_pointer : etl::true_type {}; + template struct is_member_function_pointer : etl::true_type {}; + template struct is_member_function_pointer : etl::true_type {}; + +#if ETL_HAS_NOEXCEPT_FUNCTION_TYPE + template struct is_member_function_pointer : etl::true_type {}; + template struct is_member_function_pointer : etl::true_type {}; + template struct is_member_function_pointer : etl::true_type {}; + template struct is_member_function_pointer : etl::true_type {}; +#endif + + template struct is_member_function_pointer : etl::true_type {}; + template struct is_member_function_pointer : etl::true_type {}; + template struct is_member_function_pointer : etl::true_type {}; + template struct is_member_function_pointer : etl::true_type {}; + template struct is_member_function_pointer : etl::true_type {}; + template struct is_member_function_pointer : etl::true_type {}; + template struct is_member_function_pointer : etl::true_type {}; + template struct is_member_function_pointer: etl::true_type {}; + +#if ETL_HAS_NOEXCEPT_FUNCTION_TYPE + template struct is_member_function_pointer : etl::true_type {}; + template struct is_member_function_pointer : etl::true_type {}; + template struct is_member_function_pointer : etl::true_type {}; + template struct is_member_function_pointer : etl::true_type {}; + + template struct is_member_function_pointer : etl::true_type {}; + template struct is_member_function_pointer : etl::true_type {}; + template struct is_member_function_pointer : etl::true_type {}; + template struct is_member_function_pointer: etl::true_type {}; +#endif + +#if ETL_USING_CPP17 + template + inline constexpr bool is_member_function_pointer_v = etl::is_member_function_pointer::value; +#endif + + //*************************************************************************** + /// Is T a member object pointer + //*************************************************************************** + namespace private_type_traits + { + template + struct logical_not_t : etl::integral_constant {}; + + template + struct is_member_object_pointer_helper : public etl::false_type {}; + + template + struct is_member_object_pointer_helper : public logical_not_t>::type {}; + } + + template struct is_member_object_pointer : public private_type_traits::is_member_object_pointer_helper>::type {}; + +#if ETL_USING_CPP17 + template + inline constexpr bool is_member_object_pointer_v = etl::is_member_object_pointer::value; +#endif } // Helper macros diff --git a/include/etl/type_traits.h b/include/etl/type_traits.h index 3c9ac66b..44dccad6 100644 --- a/include/etl/type_traits.h +++ b/include/etl/type_traits.h @@ -788,6 +788,7 @@ namespace etl //*************************************************************************** /// is_convertible + ///\ingroup type_traits #if ETL_USING_CPP11 namespace private_type_traits { @@ -816,11 +817,34 @@ namespace etl decltype(private_type_traits::nonvoid_convertible(0))::value) || (etl::is_void::value && etl::is_void::value)> {}; #endif + + // Is convertible and the conversion is noexcept. + template + struct is_nothrow_convertible + { + private: + // Helper: a function taking TTo to require the conversion. + static void sink(TTo) noexcept; + + // Selected only if 'sink(declval())' is a valid expression. + template + static auto test(int) -> etl::bool_constant()))>; + + // Fallback if conversion is not viable. + template + static etl::false_type test(...); + + public: + static ETL_CONSTANT bool value = decltype(test(0))::value; + }; #endif #if ETL_USING_CPP17 template inline constexpr bool is_convertible_v = etl::is_convertible::value; + + template + inline constexpr bool is_nothrow_convertible_v = etl::is_nothrow_convertible::value; #endif //*************************************************************************** @@ -1341,11 +1365,34 @@ typedef integral_constant true_type; #if ETL_USING_CPP11 template struct is_convertible : std::is_convertible {}; + + // Is convertible and the conversion is noexcept. + template + struct is_nothrow_convertible + { + private: + // Helper: a function taking TTo to require the conversion. + static void sink(TTo) noexcept; + + // Selected only if 'sink(declval())' is a valid expression. + template + static auto test(int) -> etl::bool_constant()))>; + + // Fallback if conversion is not viable. + template + static etl::false_type test(...); + + public: + static ETL_CONSTANT bool value = decltype(test(0))::value; + }; #endif #if ETL_USING_CPP17 template inline constexpr bool is_convertible_v = std::is_convertible_v; + + template + inline constexpr bool is_nothrow_convertible_v = is_nothrow_convertible::value; #endif //*************************************************************************** @@ -2117,17 +2164,17 @@ typedef integral_constant true_type; /// is_constructible namespace private_type_traits { - template + template struct is_constructible_ : etl::false_type {}; - template - struct is_constructible_()...))>, T, Args...> : etl::true_type {}; + template + struct is_constructible_()...))>, T, TArgs...> : etl::true_type {}; } //********************************************* // is_constructible - template - using is_constructible = private_type_traits::is_constructible_, T, Args...>; + template + using is_constructible = private_type_traits::is_constructible_, T, TArgs...>; //********************************************* // is_copy_constructible @@ -2497,13 +2544,228 @@ typedef integral_constant true_type; return false; } #elif ETL_USING_BUILTIN_IS_CONSTANT_EVALUATED == 1 - // fallback for C++20 on supported compilers + // Fallback for C++20 on supported compilers return __builtin_is_constant_evaluated(); #else // default if unsupported return false; #endif } + +#if ETL_USING_CPP11 + //********************************* + /// Check if T is a function type + //********************************* + template + struct is_function : etl::false_type + { + }; + + // Plain / cv-qualified + template + struct is_function : etl::true_type {}; + template + struct is_function : etl::true_type {}; + template + struct is_function : etl::true_type {}; + template + struct is_function : etl::true_type {}; + + // Variadic + template + struct is_function : etl::true_type {}; + + // noexcept variants (if supported by the toolchain) +#if ETL_HAS_NOEXCEPT_FUNCTION_TYPE + template + struct is_function : etl::true_type {}; + template + struct is_function : etl::true_type {}; + template + struct is_function : etl::true_type {}; + template + struct is_function : etl::true_type {}; + template + struct is_function : etl::true_type {}; +#endif + +#if ETL_USING_CPP17 + template + inline constexpr bool is_function_v = etl::is_function::value; +#endif +#endif + +#if ETL_USING_CPP11 + //********************************* + /// Check for the presence of operator() + //********************************* + template >::value, int> = 0> + struct has_call_operator + { + template + static auto test(int) -> decltype(&U::operator(), etl::true_type()); + + template + static etl::false_type test(...); + + static const bool value = etl::is_same(0)), etl::true_type>::value; + }; + +#if ETL_USING_CPP17 + template + inline constexpr bool has_call_operator_v = etl::has_call_operator::value; +#endif +#endif + +#if ETL_USING_CPP11 + //*************************************************************************** + /// Check that there is only one operator() + //*************************************************************************** + template >::value, int> = 0> + struct has_unique_call_operator + { + //********************************* + // Test for presence of operator() + //********************************* + template + static auto test(int) -> decltype(&U::operator(), etl::true_type()); + + //********************************* + // Fallback + //********************************* + template + static auto test(...) -> etl::false_type; + + //********************************* + // true if operator() exists and is unique + //********************************* + static const bool value = decltype(test>(0))::value; + }; + +#if ETL_USING_CPP17 + template + inline constexpr bool has_unique_call_operator_v = etl::has_unique_call_operator::value; +#endif +#endif + + //*************************************************************************** + /// Is T a member pointer + //*************************************************************************** + namespace private_type_traits + { + template + struct is_member_pointer_helper : etl::false_type {}; + + template + struct is_member_pointer_helper : etl::true_type {}; + } + + template + struct is_member_pointer : private_type_traits::is_member_pointer_helper> {}; + +#if ETL_USING_CPP17 + template + inline constexpr bool is_member_pointer_v = etl::is_member_pointer::value; +#endif + + //*************************************************************************** + /// Is T a member function pointer + //*************************************************************************** + template struct is_member_function_pointer : etl::false_type {}; + + template struct is_member_function_pointer : etl::true_type {}; + template struct is_member_function_pointer : etl::true_type {}; + template struct is_member_function_pointer : etl::true_type {}; + template struct is_member_function_pointer : etl::true_type {}; + +#if ETL_HAS_NOEXCEPT_FUNCTION_TYPE + template struct is_member_function_pointer : etl::true_type {}; + template struct is_member_function_pointer : etl::true_type {}; + template struct is_member_function_pointer : etl::true_type {}; + template struct is_member_function_pointer : etl::true_type {}; +#endif + + template struct is_member_function_pointer : etl::true_type {}; + template struct is_member_function_pointer : etl::true_type {}; + template struct is_member_function_pointer : etl::true_type {}; + template struct is_member_function_pointer : etl::true_type {}; + + template struct is_member_function_pointer : etl::true_type {}; + template struct is_member_function_pointer : etl::true_type {}; + template struct is_member_function_pointer : etl::true_type {}; + template struct is_member_function_pointer: etl::true_type {}; + +#if ETL_HAS_NOEXCEPT_FUNCTION_TYPE + template struct is_member_function_pointer : etl::true_type {}; + template struct is_member_function_pointer : etl::true_type {}; + template struct is_member_function_pointer : etl::true_type {}; + template struct is_member_function_pointer : etl::true_type {}; + + template struct is_member_function_pointer : etl::true_type {}; + template struct is_member_function_pointer : etl::true_type {}; + template struct is_member_function_pointer : etl::true_type {}; + template struct is_member_function_pointer: etl::true_type {}; +#endif + + template struct is_member_function_pointer : etl::true_type {}; + template struct is_member_function_pointer : etl::true_type {}; + template struct is_member_function_pointer : etl::true_type {}; + template struct is_member_function_pointer : etl::true_type {}; + +#if ETL_HAS_NOEXCEPT_FUNCTION_TYPE + template struct is_member_function_pointer : etl::true_type {}; + template struct is_member_function_pointer : etl::true_type {}; + template struct is_member_function_pointer : etl::true_type {}; + template struct is_member_function_pointer : etl::true_type {}; +#endif + + template struct is_member_function_pointer : etl::true_type {}; + template struct is_member_function_pointer : etl::true_type {}; + template struct is_member_function_pointer : etl::true_type {}; + template struct is_member_function_pointer : etl::true_type {}; + template struct is_member_function_pointer : etl::true_type {}; + template struct is_member_function_pointer : etl::true_type {}; + template struct is_member_function_pointer : etl::true_type {}; + template struct is_member_function_pointer: etl::true_type {}; + +#if ETL_HAS_NOEXCEPT_FUNCTION_TYPE + template struct is_member_function_pointer : etl::true_type {}; + template struct is_member_function_pointer : etl::true_type {}; + template struct is_member_function_pointer : etl::true_type {}; + template struct is_member_function_pointer : etl::true_type {}; + + template struct is_member_function_pointer : etl::true_type {}; + template struct is_member_function_pointer : etl::true_type {}; + template struct is_member_function_pointer : etl::true_type {}; + template struct is_member_function_pointer: etl::true_type {}; +#endif + +#if ETL_USING_CPP17 + template + inline constexpr bool is_member_function_pointer_v = etl::is_member_function_pointer::value; +#endif + + //*************************************************************************** + /// Is T a member object pointer + //*************************************************************************** + namespace private_type_traits + { + template + struct logical_not_t : etl::integral_constant {}; + + template + struct is_member_object_pointer_helper : public etl::false_type {}; + + template + struct is_member_object_pointer_helper : public logical_not_t>::type {}; + } + + template struct is_member_object_pointer : public private_type_traits::is_member_object_pointer_helper>::type {}; + +#if ETL_USING_CPP17 + template + inline constexpr bool is_member_object_pointer_v = etl::is_member_object_pointer::value; +#endif } // Helper macros diff --git a/test/vs2022/etl.vcxproj b/test/vs2022/etl.vcxproj index d2b13bec..095d407d 100644 --- a/test/vs2022/etl.vcxproj +++ b/test/vs2022/etl.vcxproj @@ -1003,87 +1003,104 @@ true true - $(Configuration)\ + Build\$(Configuration)\ + $(SolutionDir)Build\$(Configuration)\ true true - $(Configuration)\ + Build\$(Configuration)\ + $(SolutionDir)Build\$(Configuration)\ true true - $(Configuration)\ + Build\$(Configuration)\ + $(SolutionDir)Build\$(Configuration)\ true true - $(Configuration)\ + Build\$(Configuration)\ + $(SolutionDir)Build\$(Configuration)\ true true - $(Configuration)\ + Build\$(Configuration)\ + $(SolutionDir)Build\$(Configuration)\ true true - $(Configuration)\ + Build\$(Configuration)\ + $(SolutionDir)Build\$(Configuration)\ true true - $(Configuration)\ + Build\$(Configuration)\ + $(SolutionDir)Build\$(Configuration)\ true true - $(Configuration)\ + Build\$(Configuration)\ + $(SolutionDir)Build\$(Configuration)\ true true - $(Configuration)\ + Build\$(Configuration)\ + $(SolutionDir)Build\$(Configuration)\ true true - $(Configuration)\ + Build\$(Configuration)\ + $(SolutionDir)Build\$(Configuration)\ true true - $(Configuration)\ + Build\$(Configuration)\ + $(SolutionDir)Build\$(Configuration)\ true true - $(Configuration)\ + Build\$(Configuration)\ + $(SolutionDir)Build\$(Configuration)\ true true - $(Configuration)\ + Build\$(Configuration)\ + $(SolutionDir)Build\$(Configuration)\ true true - $(Configuration)\ + Build\$(Configuration)\ + $(SolutionDir)Build\$(Configuration)\ true true - $(Configuration)\ + Build\$(Configuration)\ + $(SolutionDir)Build\$(Configuration)\ true true - $(Configuration)\ + Build\$(Configuration)\ + $(SolutionDir)Build\$(Configuration)\ true true - $(Configuration)\ + Build\$(Configuration)\ + $(SolutionDir)Build\$(Configuration)\ false @@ -1129,7 +1146,8 @@ true true - $(Configuration)\ + Build\$(Configuration)\ + $(SolutionDir)Build\$(Configuration)\ false