From ce0db9b968fb1488f8d2d2f9c7c56b178f70dbfb Mon Sep 17 00:00:00 2001 From: Michele Caini Date: Mon, 12 Oct 2020 10:28:10 +0200 Subject: [PATCH] type_list: removed type_list_size[_v] in favor of type_list::size (breaking changes) and added operator+ for type lists --- src/entt/core/type_traits.hpp | 62 ++++++---------------------------- src/entt/entity/organizer.hpp | 12 +++---- test/entt/core/type_traits.cpp | 5 +-- 3 files changed, 19 insertions(+), 60 deletions(-) diff --git a/src/entt/core/type_traits.hpp b/src/entt/core/type_traits.hpp index 4f370aa40..d71376175 100644 --- a/src/entt/core/type_traits.hpp +++ b/src/entt/core/type_traits.hpp @@ -96,44 +96,16 @@ template inline constexpr choice_t choice{}; -/*! @brief A class to use to push around lists of types, nothing more. */ -template -struct type_list {}; - - -/*! @brief Primary template isn't defined on purpose. */ -template -struct type_list_size; - - /** - * @brief Compile-time number of elements in a type list. + * @brief A class to use to push around lists of types, nothing more. * @tparam Type Types provided by the type list. */ template -struct type_list_size> - : std::integral_constant -{}; - - -/** - * @brief Helper variable template. - * @tparam List Type list. - */ -template -inline constexpr auto type_list_size_v = type_list_size::value; - - -/*! @brief Primary template isn't defined on purpose. */ -template -struct type_list_cat; - - -/*! @brief Concatenates multiple type lists. */ -template<> -struct type_list_cat<> { - /*! @brief A type list composed by the types of all the type lists. */ - using type = type_list<>; +struct type_list { + /*! @brief Type list type. */ + using type = type_list; + /*! @brief Compile-time number of elements in the type list. */ + static constexpr auto size = sizeof...(Type); }; @@ -141,24 +113,10 @@ struct type_list_cat<> { * @brief Concatenates multiple type lists. * @tparam Type Types provided by the first type list. * @tparam Other Types provided by the second type list. - * @tparam List Other type lists, if any. + * @return A type list composed by the types of both the type lists. */ -template -struct type_list_cat, type_list, List...> { - /*! @brief A type list composed by the types of all the type lists. */ - using type = typename type_list_cat, List...>::type; -}; - - -/** - * @brief Concatenates multiple type lists. - * @tparam Type Types provided by the type list. - */ -template -struct type_list_cat> { - /*! @brief A type list composed by the types of all the type lists. */ - using type = type_list; -}; +template +constexpr type_list operator+(type_list, type_list) { return {}; } /** @@ -166,7 +124,7 @@ struct type_list_cat> { * @tparam List Type lists to concatenate. */ template -using type_list_cat_t = typename type_list_cat::type; +using type_list_cat_t = decltype((type_list<>{} + ... + List{})); /*! @brief Primary template isn't defined on purpose. */ diff --git a/src/entt/entity/organizer.hpp b/src/entt/entity/organizer.hpp index 4abc834cb..8f7cababb 100644 --- a/src/entt/entity/organizer.hpp +++ b/src/entt/entity/organizer.hpp @@ -381,8 +381,8 @@ public: track_dependencies(vertices.size(), requires_registry, typename resource_type::ro{}, typename resource_type::rw{}); vertices.push_back({ - type_list_size_v, - type_list_size_v, + resource_type::ro::size, + resource_type::rw::size, name, nullptr, callback, @@ -414,8 +414,8 @@ public: track_dependencies(vertices.size(), requires_registry, typename resource_type::ro{}, typename resource_type::rw{}); vertices.push_back({ - type_list_size_v, - type_list_size_v, + resource_type::ro::size, + resource_type::rw::size, name, &value_or_instance, callback, @@ -443,8 +443,8 @@ public: track_dependencies(vertices.size(), true, typename resource_type::ro{}, typename resource_type::rw{}); vertices.push_back({ - type_list_size_v, - type_list_size_v, + resource_type::ro::size, + resource_type::rw::size, name, payload, func, diff --git a/test/entt/core/type_traits.cpp b/test/entt/core/type_traits.cpp index 2b76445e7..8bfe1f231 100644 --- a/test/entt/core/type_traits.cpp +++ b/test/entt/core/type_traits.cpp @@ -46,9 +46,10 @@ TEST(TypeTraits, TypeList) { using type = entt::type_list; using other = entt::type_list; - static_assert(entt::type_list_size_v == 2u); - static_assert(entt::type_list_size_v == 1u); + static_assert(type::size == 2u); + static_assert(other::size == 1u); + static_assert(std::is_same_v>); static_assert(std::is_same_v, entt::type_list>); static_assert(std::is_same_v, entt::type_list>); static_assert(std::is_same_v, entt::type_list>);