Added type_list_is_empty

This commit is contained in:
John Wellbelove 2026-02-19 13:29:11 +00:00
parent 2ba5e93d01
commit 9ebcf41e63
2 changed files with 30 additions and 7 deletions

View File

@ -623,6 +623,29 @@ namespace etl
inline constexpr bool type_list_is_unique_v = etl::type_list_is_unique<TTypeList>::value;
#endif
//***************************************************************************
/// Check if the type_list is empty.
//***************************************************************************
template <typename T>
struct type_list_is_empty;
template <>
struct type_list_is_empty<etl::type_list<>>
: etl::true_type
{
};
template <typename... TTypes>
struct type_list_is_empty<etl::type_list<TTypes...>>
: etl::false_type
{
};
#if ETL_USING_CPP17
template <typename... TTypes>
inline constexpr bool type_list_is_empty_v = type_list_is_empty<TTypes...>::value;
#endif
//***************************************************************************
/// Checks that all types in a type_list satisfy a unary predicate.
/// Predicate must be: template <typename T> struct Pred : etl::bool_constant<...> {};

View File

@ -714,17 +714,17 @@ namespace
}
//*************************************************************************
TEST(test_type_list_is_unique_for_non_empty_list)
TEST(test_type_list_is_empty)
{
using list1 = etl::type_list<A, B, C>;
using list2 = etl::type_list<A, B, C, A>;
using list1 = etl::type_list<>;
using list2 = etl::type_list<A>;
CHECK_TRUE((etl::type_list_is_unique<list1>::value));
CHECK_FALSE((etl::type_list_is_unique<list2>::value));
CHECK_TRUE((etl::type_list_is_empty<list1>::value));
CHECK_FALSE((etl::type_list_is_empty<list2>::value));
#if ETL_USING_CPP17
CHECK_TRUE((etl::type_list_is_unique_v<list1>));
CHECK_FALSE((etl::type_list_is_unique_v<list2>));
CHECK_TRUE((etl::type_list_is_empty_v<list1>));
CHECK_FALSE((etl::type_list_is_empty_v<list2>));
#endif
}
}