diff --git a/TODO b/TODO index 72f4bfa6a..e728160ab 100644 --- a/TODO +++ b/TODO @@ -26,4 +26,4 @@ * hashed string: static (constexpr) member function to_value for direct hashing * entity: simplify get functions so as to generate less symbols for multiple components * events on replace, so that one can track updated components? indagate impact -* add merge functionality for type list +* allow to bind values to delegate on connect with free functions (sbo + check size on costruction to guarantee a zero allocation abstraction) diff --git a/src/entt/core/type_traits.hpp b/src/entt/core/type_traits.hpp index 99e6b48eb..c37716b80 100644 --- a/src/entt/core/type_traits.hpp +++ b/src/entt/core/type_traits.hpp @@ -10,6 +10,30 @@ template struct type_list {}; +/** + * @brief Concatenates multiple type lists into one. + * @tparam Type List of types. + * @return The given type list. + */ +template +constexpr auto type_list_cat(type_list = type_list<>{}) { + return type_list{}; +} + + +/** + * @brief Concatenates multiple type lists into one. + * @tparam Type List of types. + * @tparam Other List of types. + * @tparam List Type list instances. + * @return A type list that is the concatenation of the given type lists. + */ +template +constexpr auto type_list_cat(type_list, type_list, List...) { + return type_list_cat(type_list{}, List{}...); +} + + } diff --git a/src/entt/entity/registry.hpp b/src/entt/entity/registry.hpp index de9c7463a..b92768faf 100644 --- a/src/entt/entity/registry.hpp +++ b/src/entt/entity/registry.hpp @@ -1161,7 +1161,7 @@ public: * @return A newly created persistent view. */ template - entt::persistent_view persistent_view(type_list = type_list<>{}) { + entt::persistent_view persistent_view(type_list = {}) { static_assert(sizeof...(Component)); using handler_type = handler_pool, type_list>; const auto htype = handler_family::type; @@ -1196,7 +1196,7 @@ public: /*! @copydoc persistent_view */ template - inline entt::persistent_view persistent_view(type_list = type_list<>{}) const { + inline entt::persistent_view persistent_view(type_list = {}) const { static_assert(std::conjunction_v...>); return const_cast(this)->persistent_view(type_list{}); } @@ -1294,7 +1294,7 @@ public: * @param reg A valid reference to a source registry. */ template - void clone(const registry ®) { + void clone(const registry ®, type_list = {}) { *this = {}; (assure(), ...); diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index eb3e37bb2..4776d5982 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -63,6 +63,7 @@ SETUP_AND_ADD_TEST(family entt/core/family.cpp) SETUP_AND_ADD_TEST(hashed_string entt/core/hashed_string.cpp) SETUP_AND_ADD_TEST(ident entt/core/ident.cpp) SETUP_AND_ADD_TEST(monostate entt/core/monostate.cpp) +SETUP_AND_ADD_TEST(type_traits entt/core/type_traits.cpp) SETUP_AND_ADD_TEST(utility entt/core/utility.cpp) # Test entity diff --git a/test/entt/core/type_traits.cpp b/test/entt/core/type_traits.cpp new file mode 100644 index 000000000..ef77c1330 --- /dev/null +++ b/test/entt/core/type_traits.cpp @@ -0,0 +1,22 @@ +#include +#include +#include + +TEST(TypeTraits, TypeList) { + static_assert(std::is_same_v< + decltype(entt::type_list_cat()), + entt::type_list<> + >); + + static_assert(std::is_same_v< + decltype(entt::type_list_cat(entt::type_list{})), + entt::type_list + >); + + static_assert(std::is_same_v< + decltype(entt::type_list_cat(entt::type_list{}, entt::type_list<>{}, entt::type_list{})), + entt::type_list + >); + + SUCCEED(); +} diff --git a/test/mod/mod.cpp b/test/mod/mod.cpp index eae29eb7b..e81bb29cd 100644 --- a/test/mod/mod.cpp +++ b/test/mod/mod.cpp @@ -127,13 +127,11 @@ class duktape_registry { struct func_map { using func_type = duk_ret_t(*)(duk_context *, entt::registry<> &); - using test_type = bool(entt::registry<>:: *)(entt::registry<>::entity_type) const; func_type set; func_type unset; func_type has; func_type get; - test_type test; }; template @@ -142,8 +140,7 @@ class duktape_registry { &::set, &::unset, &::has, - &::get, - &entt::registry<>::has + &::get }), ...); }