From 4b8ab3eeda06f7779c6ee71e36bfa70a517d42a0 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Mon, 13 Oct 2025 23:02:45 +0100 Subject: [PATCH] Added type_list_has_duplicates_of and type_list_count_of --- include/etl/type_list.h | 46 +++++++++++++++++++++++++++++++++++ test/test_type_list.cpp | 54 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+) diff --git a/include/etl/type_list.h b/include/etl/type_list.h index 2042ff79..eeea5052 100644 --- a/include/etl/type_list.h +++ b/include/etl/type_list.h @@ -205,6 +205,52 @@ namespace etl inline constexpr bool type_list_contains_v = etl::type_list_contains::value; #endif + //*************************************************************************** + /// Defines a bool constant that is true if the type_list has duplicates of the specified type, otherwise false. + //*************************************************************************** + template + struct type_list_has_duplicates_of; + + template + struct type_list_has_duplicates_of, T> + : public etl::has_duplicates_of + { + }; + + template + struct type_list_has_duplicates_of, T> + : public etl::integral_constant + { + }; + +#if ETL_USING_CPP17 + template + inline constexpr bool type_list_has_duplicates_of_v = etl::type_list_has_duplicates_of::value; +#endif + + //*************************************************************************** + /// Defines an integral constant that is the count of the number of times a type is in the type list. + //*************************************************************************** + template + struct type_list_count_of; + + template + struct type_list_count_of, T> + : public etl::count_of + { + }; + + template + struct type_list_count_of, T> + : public etl::integral_constant + { + }; + +#if ETL_USING_CPP17 + template + inline constexpr size_t type_list_count_of_v = etl::type_list_count_of::value; +#endif + //*************************************************************************** /// Defines an integral constant that is maximum sizeof all types in the type_list. /// If the type_list is empty, then defined as 0. diff --git a/test/test_type_list.cpp b/test/test_type_list.cpp index 5cd253d0..df37af51 100644 --- a/test/test_type_list.cpp +++ b/test/test_type_list.cpp @@ -105,6 +105,60 @@ namespace #endif } + //************************************************************************* + TEST(test_type_list_has_duplicates_of) + { + typedef etl::type_list t1; + typedef etl::type_list t2; + typedef etl::type_list t3; + typedef etl::type_list<> t4; + + CHECK_FALSE((etl::type_list_has_duplicates_of::value)); + CHECK_FALSE((etl::type_list_has_duplicates_of::value)); + CHECK_FALSE((etl::type_list_has_duplicates_of::value)); + CHECK_TRUE((etl::type_list_has_duplicates_of::value)); + CHECK_FALSE((etl::type_list_has_duplicates_of::value)); + CHECK_FALSE((etl::type_list_has_duplicates_of::value)); + CHECK_FALSE((etl::type_list_has_duplicates_of::value)); + +#if ETL_USING_CPP17 + CHECK_FALSE((etl::type_list_has_duplicates_of_v)); + CHECK_FALSE((etl::type_list_has_duplicates_of_v)); + CHECK_FALSE((etl::type_list_has_duplicates_of_v)); + CHECK_TRUE((etl::type_list_has_duplicates_of_v)); + CHECK_FALSE((etl::type_list_has_duplicates_of_v)); + CHECK_FALSE((etl::type_list_has_duplicates_of_v)); + CHECK_FALSE((etl::type_list_has_duplicates_of_v)); +#endif + } + + //************************************************************************* + TEST(test_type_list_count_of) + { + typedef etl::type_list t1; + typedef etl::type_list t2; + typedef etl::type_list t3; + typedef etl::type_list<> t4; + + CHECK_EQUAL(1, (etl::type_list_count_of::value)); + CHECK_EQUAL(0, (etl::type_list_count_of::value)); + CHECK_EQUAL(0, (etl::type_list_count_of::value)); + CHECK_EQUAL(2, (etl::type_list_count_of::value)); + CHECK_EQUAL(1, (etl::type_list_count_of::value)); + CHECK_EQUAL(0, (etl::type_list_count_of::value)); + CHECK_EQUAL(0, (etl::type_list_count_of::value)); + +#if ETL_USING_CPP17 + CHECK_EQUAL(1, (etl::type_list_count_of_v)); + CHECK_EQUAL(0, (etl::type_list_count_of_v)); + CHECK_EQUAL(0, (etl::type_list_count_of_v)); + CHECK_EQUAL(2, (etl::type_list_count_of_v)); + CHECK_EQUAL(1, (etl::type_list_count_of_v)); + CHECK_EQUAL(0, (etl::type_list_count_of_v)); + CHECK_EQUAL(0, (etl::type_list_count_of_v)); +#endif + } + //************************************************************************* TEST(test_type_list_index_of_type) {