diff --git a/include/etl/generators/type_traits_generator.h b/include/etl/generators/type_traits_generator.h index 6842eb06..5a1aadcc 100644 --- a/include/etl/generators/type_traits_generator.h +++ b/include/etl/generators/type_traits_generator.h @@ -725,7 +725,8 @@ namespace etl { // Base case template - struct is_convertible_to_int : false_type + struct is_convertible_to_int + : false_type { }; @@ -733,7 +734,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 { }; } @@ -751,7 +752,29 @@ namespace etl template inline constexpr bool is_enum_v = etl::is_enum::value; #endif +#else + namespace private_type_traits + { + // Helper to detect if a type is convertible to an integer + template + struct is_convertible_to_int + { + static char test(int); // Match if T is convertible to int + static double test(...); // Fallback for other types + static const bool value = sizeof(test(static_cast(0))) == sizeof(char); + }; + } + + // Implementation of is_enum + template + struct is_enum + { + static const bool value = private_type_traits::is_convertible_to_int::value && + !is_class::value && + !is_arithmetic::value && + !is_reference::value; + }; #endif //*************************************************************************** @@ -2257,7 +2280,8 @@ typedef integral_constant true_type; }; template - struct common_type_2_impl : decay_conditional_result + struct common_type_2_impl + : decay_conditional_result { }; @@ -2354,7 +2378,7 @@ typedef integral_constant true_type; //********************************************* // underlying_type - +#if ETL_USING_BUILTIN_UNDERLYING_TYPE // Primary template for etl::underlying_type template ::value> struct underlying_type; @@ -2367,37 +2391,19 @@ typedef integral_constant true_type; ETL_STATIC_ASSERT(etl::is_enum::value, "etl::underlying_type can only be used with enumeration types."); }; -#if ETL_USING_BUILTIN_UNDERLYING_TYPE template struct underlying_type { typedef __underlying_type(T) type; }; #else + /// Primary template for etl::underlying_type + /// Users must spelialise this template for their enumerations. template - struct underlying_type + struct underlying_type { - private: - - // Helper union to deduce the underlying type - union Helper - { - T enum_value; - unsigned char raw[sizeof(T)]; - }; - - public: - - // The deduced underlying type - typedef typename etl::conditional::type>::type>::type>::type type; + ETL_STATIC_ASSERT(false, "No user defined specialisation of etl::underlying_type for this type"); + typedef char type; }; #endif diff --git a/include/etl/type_traits.h b/include/etl/type_traits.h index 1af56e92..46d296c4 100644 --- a/include/etl/type_traits.h +++ b/include/etl/type_traits.h @@ -713,7 +713,8 @@ namespace etl { // Base case template - struct is_convertible_to_int : false_type + struct is_convertible_to_int + : false_type { }; @@ -721,7 +722,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 { }; } @@ -2389,6 +2390,8 @@ typedef integral_constant true_type; typedef __underlying_type(T) type; }; #else + /// Primary template for etl::underlying_type + /// Users must spelialise this template for their enumerations. template struct underlying_type { @@ -2398,8 +2401,6 @@ typedef integral_constant true_type; #endif #if ETL_USING_CPP11 - /// Primary template for etl::underlying_type - /// Users must spelialise this template for their enumerations. template using underlying_type_t = typename underlying_type::type; #endif