diff --git a/include/etl/type_list.h b/include/etl/type_list.h index 7e0a6e8a..293c9dc3 100644 --- a/include/etl/type_list.h +++ b/include/etl/type_list.h @@ -606,6 +606,23 @@ namespace etl using type_list_unique_t = typename etl::type_list_unique::type; #endif + //*************************************************************************** + /// Checks that all of the types in a type_list are unique. + //*************************************************************************** + template + struct type_list_is_unique + // Create a unique version of the type list, and check if it is the same as the original list. + // If they are the same, then all types in the original list are unique. + : etl::bool_constant::type>::value> + { + ETL_STATIC_ASSERT((etl::is_type_list::value), "TTypeList must be an etl::type_list"); + }; + +#if ETL_USING_CPP17 + template + inline constexpr bool type_list_is_unique_v = etl::type_list_is_unique::value; +#endif + //*************************************************************************** /// Checks that all types in a type_list satisfy a unary predicate. /// Predicate must be: template struct Pred : etl::bool_constant<...> {}; diff --git a/test/test_type_list.cpp b/test/test_type_list.cpp index 97c00095..1953ef96 100644 --- a/test/test_type_list.cpp +++ b/test/test_type_list.cpp @@ -698,6 +698,33 @@ namespace CHECK_TRUE((etl::type_list_none_of_v)); CHECK_FALSE((etl::type_list_none_of_v)); CHECK_TRUE((etl::type_list_none_of_v)); +#endif + } + + //************************************************************************* + TEST(test_type_list_is_unique_for_empty_list) + { + using list1 = etl::type_list<>; + + CHECK_TRUE((etl::type_list_is_unique::value)); + +#if ETL_USING_CPP17 + CHECK_TRUE((etl::type_list_is_unique_v)); +#endif + } + + //************************************************************************* + TEST(test_type_list_is_unique_for_non_empty_list) + { + using list1 = etl::type_list; + using list2 = etl::type_list; + + CHECK_TRUE((etl::type_list_is_unique::value)); + CHECK_FALSE((etl::type_list_is_unique::value)); + +#if ETL_USING_CPP17 + CHECK_TRUE((etl::type_list_is_unique_v)); + CHECK_FALSE((etl::type_list_is_unique_v)); #endif } }