mirror of
https://github.com/ETLCPP/etl.git
synced 2026-04-30 19:09:10 +08:00
Added etl::type_list_is_unique
This commit is contained in:
parent
25b88e509b
commit
2ba5e93d01
@ -606,6 +606,23 @@ namespace etl
|
||||
using type_list_unique_t = typename etl::type_list_unique<TTypeList>::type;
|
||||
#endif
|
||||
|
||||
//***************************************************************************
|
||||
/// Checks that all of the types in a type_list are unique.
|
||||
//***************************************************************************
|
||||
template <typename TTypeList>
|
||||
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<std::is_same<TTypeList, typename type_list_unique<TTypeList>::type>::value>
|
||||
{
|
||||
ETL_STATIC_ASSERT((etl::is_type_list<TTypeList>::value), "TTypeList must be an etl::type_list");
|
||||
};
|
||||
|
||||
#if ETL_USING_CPP17
|
||||
template <typename TTypeList>
|
||||
inline constexpr bool type_list_is_unique_v = etl::type_list_is_unique<TTypeList>::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<...> {};
|
||||
|
||||
@ -698,6 +698,33 @@ namespace
|
||||
CHECK_TRUE((etl::type_list_none_of_v<list2, is_type_a>));
|
||||
CHECK_FALSE((etl::type_list_none_of_v<list2, is_type_b>));
|
||||
CHECK_TRUE((etl::type_list_none_of_v<list2, is_type_c>));
|
||||
#endif
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_type_list_is_unique_for_empty_list)
|
||||
{
|
||||
using list1 = etl::type_list<>;
|
||||
|
||||
CHECK_TRUE((etl::type_list_is_unique<list1>::value));
|
||||
|
||||
#if ETL_USING_CPP17
|
||||
CHECK_TRUE((etl::type_list_is_unique_v<list1>));
|
||||
#endif
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_type_list_is_unique_for_non_empty_list)
|
||||
{
|
||||
using list1 = etl::type_list<A, B, C>;
|
||||
using list2 = etl::type_list<A, B, C, A>;
|
||||
|
||||
CHECK_TRUE((etl::type_list_is_unique<list1>::value));
|
||||
CHECK_FALSE((etl::type_list_is_unique<list2>::value));
|
||||
|
||||
#if ETL_USING_CPP17
|
||||
CHECK_TRUE((etl::type_list_is_unique_v<list1>));
|
||||
CHECK_FALSE((etl::type_list_is_unique_v<list2>));
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user