diff --git a/include/etl/generators/type_traits_generator.h b/include/etl/generators/type_traits_generator.h index 35db7ea6..c1d73d10 100644 --- a/include/etl/generators/type_traits_generator.h +++ b/include/etl/generators/type_traits_generator.h @@ -2295,6 +2295,17 @@ typedef integral_constant true_type; template using signed_type_t = typename signed_type::type; #endif + +//********************************************* +// type_identity + +template +struct type_identity { typedef T type; }; + +#if ETL_USING_CPP11 + template + using type_identity_t = typename type_identity::type; +#endif } // Helper macros diff --git a/include/etl/type_traits.h b/include/etl/type_traits.h index 93730e5a..1a40f026 100644 --- a/include/etl/type_traits.h +++ b/include/etl/type_traits.h @@ -2288,6 +2288,17 @@ typedef integral_constant true_type; template using signed_type_t = typename signed_type::type; #endif + +//********************************************* +// type_identity + +template +struct type_identity { typedef T type; }; + +#if ETL_USING_CPP11 + template + using type_identity_t = typename type_identity::type; +#endif } // Helper macros diff --git a/test/test_type_traits.cpp b/test/test_type_traits.cpp index 129a5fa8..fc9e7070 100644 --- a/test/test_type_traits.cpp +++ b/test/test_type_traits.cpp @@ -122,6 +122,13 @@ namespace NotDefaultConstructible(NotDefaultConstructible&&) = delete; NotDefaultConstructible& operator =(NotDefaultConstructible&) = delete; }; + + // A function to test etl::type_identity. + template + T type_identity_test_add(T first, typename etl::type_identity::type second) + { + return first + second; + } } // Definitions for when the STL and compiler built-ins are not available. @@ -1320,4 +1327,9 @@ namespace CHECK_FALSE(bool(etl::is_base_of_all::value)); #endif } + + //************************************************************************* + TEST(test_type_identity) { + CHECK_CLOSE(type_identity_test_add(1.5f, 2), 3.5f, 0.01f); + } }