From 9ce07ff617dd53d6351ff6fc4fe9e11fdc409bcf Mon Sep 17 00:00:00 2001 From: Michele Caini Date: Sun, 26 Mar 2023 12:46:27 +0200 Subject: [PATCH] type_traits: value_list_diff[_t] --- src/entt/core/type_traits.hpp | 22 ++++++++++++++++++++++ test/entt/core/type_traits.cpp | 6 ++++++ 2 files changed, 28 insertions(+) diff --git a/src/entt/core/type_traits.hpp b/src/entt/core/type_traits.hpp index 0dfdfdff0..45df48471 100644 --- a/src/entt/core/type_traits.hpp +++ b/src/entt/core/type_traits.hpp @@ -558,6 +558,28 @@ struct value_list_contains, Other> template inline constexpr bool value_list_contains_v = value_list_contains::value; +/*! @brief Primary template isn't defined on purpose. */ +template +struct value_list_diff; + +/** + * @brief Computes the difference between two value lists. + * @tparam Value Values provided by the first value list. + * @tparam Other Values provided by the second value list. + */ +template +struct value_list_diff, value_list> { + /*! @brief A value list that is the difference between the two value lists. */ + using type = value_list_cat_t, Value>, value_list<>, value_list>...>; +}; + +/** + * @brief Helper type. + * @tparam List Value lists between which to compute the difference. + */ +template +using value_list_diff_t = typename value_list_diff::type; + /*! @brief Same as std::is_invocable, but with tuples. */ template struct is_applicable: std::false_type {}; diff --git a/test/entt/core/type_traits.cpp b/test/entt/core/type_traits.cpp index 935cc7440..a6f2e4647 100644 --- a/test/entt/core/type_traits.cpp +++ b/test/entt/core/type_traits.cpp @@ -138,6 +138,12 @@ TEST(ValueList, Functionalities) { static_assert(entt::value_list_index_v<0, value> == 0u); static_assert(entt::value_list_index_v<2, value> == 1u); static_assert(entt::value_list_index_v<1, other> == 0u); + + static_assert(std::is_same_v, entt::value_list<3, 4>>, entt::value_list<0, 1, 2>>); + static_assert(std::is_same_v, entt::value_list<0, 1, 2>>, entt::value_list<>>); + static_assert(std::is_same_v, entt::value_list<0, 1>>, entt::value_list<2>>); + static_assert(std::is_same_v, entt::value_list<1, 2>>, entt::value_list<0>>); + static_assert(std::is_same_v, entt::value_list<1>>, entt::value_list<0, 2>>); } TEST(IsApplicable, Functionalities) {