From 922907890f389d46f2c54f48d7685e0918d660ea Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Thu, 26 Sep 2024 13:04:52 +0200 Subject: [PATCH] feat: `type_list_unique` added --- src/core/include/mp-units/bits/type_list.h | 22 ++++++++++++++++++++++ test/static/type_list_test.cpp | 12 ++++++++++++ 2 files changed, 34 insertions(+) diff --git a/src/core/include/mp-units/bits/type_list.h b/src/core/include/mp-units/bits/type_list.h index 636c1df1..f0e6817f 100644 --- a/src/core/include/mp-units/bits/type_list.h +++ b/src/core/include/mp-units/bits/type_list.h @@ -235,6 +235,28 @@ struct type_list_sort_impl, Pred> { template typename Pred> using type_list_sort = type_list_sort_impl::type; +// sort +template +struct type_list_unique_impl; + +template typename List> +struct type_list_unique_impl> { + using type = List<>; +}; + +template typename List, typename T, typename... Rest> +struct type_list_unique_impl> { + using type = type_list_push_front>::type, T>; +}; + +template typename List, typename T, typename... Rest> +struct type_list_unique_impl> { + using type = type_list_unique_impl>::type; +}; + +template +using type_list_unique = type_list_unique_impl::type; + } // namespace mp_units::detail MP_UNITS_DIAGNOSTIC_POP diff --git a/test/static/type_list_test.cpp b/test/static/type_list_test.cpp index 35af8b60..5db9afbb 100644 --- a/test/static/type_list_test.cpp +++ b/test/static/type_list_test.cpp @@ -189,4 +189,16 @@ static_assert(is_same_v, constant_less>, type_l static_assert(is_same_v, constant_less>, type_list>); static_assert(is_same_v, constant_less>, type_list>); +// type_list_unique + +static_assert(is_same_v>, type_list>); +static_assert(is_same_v>, type_list>); +static_assert(is_same_v>, type_list>); +static_assert(is_same_v>, type_list>); +static_assert(is_same_v>, type_list>); +static_assert(is_same_v>, type_list>); +static_assert(is_same_v>, type_list>); +static_assert(is_same_v>, type_list>); +static_assert(is_same_v>, type_list>); + } // namespace