diff --git a/include/etl/generators/type_traits_generator.h b/include/etl/generators/type_traits_generator.h index c171e35b..2eaa99e8 100644 --- a/include/etl/generators/type_traits_generator.h +++ b/include/etl/generators/type_traits_generator.h @@ -1524,7 +1524,6 @@ namespace etl }; #endif -#if ETL_CPP14_SUPPORTED template using types_t = typename types::type; @@ -1545,7 +1544,6 @@ namespace etl template using types_cpc = typename types::const_pointer_const; -#endif //*************************************************************************** /// size_of @@ -1560,8 +1558,11 @@ namespace etl //*************************************************************************** /// index_of - namespace private_type_traits + template + struct index_of { + private: + template struct index_of_helper; @@ -1582,11 +1583,9 @@ namespace etl value = 1 }; }; - } - template - struct index_of - { + public: + static ETL_CONST_OR_CONSTEXPR size_t npos = -1; enum diff --git a/include/etl/type_traits.h b/include/etl/type_traits.h index ef53e65f..53a2ce7c 100644 --- a/include/etl/type_traits.h +++ b/include/etl/type_traits.h @@ -104,6 +104,30 @@ namespace etl using bool_constant = integral_constant; #endif + //*************************************************************************** + /// bool_constant + template + struct bool_constant :etl::integral_constant + { + }; + +#if ETL_CPP17_SUPPORTED + template + inline constexpr bool bool_constant_v = bool_constant::value; +#endif + + //*************************************************************************** + /// negation + template + struct negation : etl::bool_constant + { + }; + +#if ETL_CPP17_SUPPORTED + template + inline constexpr bool negation_v = negation::value; +#endif + //*************************************************************************** /// remove_reference template struct remove_reference { typedef T type; }; @@ -1493,7 +1517,6 @@ namespace etl }; #endif -#if ETL_CPP14_SUPPORTED template using types_t = typename types::type; @@ -1514,7 +1537,6 @@ namespace etl template using types_cpc = typename types::const_pointer_const; -#endif //*************************************************************************** /// size_of @@ -1526,6 +1548,44 @@ namespace etl template inline constexpr size_t size_of_v = etl::size_of::value; #endif + + //*************************************************************************** + /// index_of + template + struct index_of + { + private: + + template + struct index_of_helper; + + template + struct index_of_helper + { + enum + { + value = etl::is_same::value ? 1 : 1 + index_of_helper::value + }; + }; + + template + struct index_of_helper + { + enum + { + value = 1 + }; + }; + + public: + + static ETL_CONST_OR_CONSTEXPR size_t npos = -1; + + enum + { + value = etl::is_one_of::value ? private_type_traits::index_of_helper::value - 1 : npos + }; + }; } #endif // ETL_TYPE_TRAITS_INCLUDED