Ver Fonte

updated core stuff

Michele Caini há 8 anos atrás
pai
commit
a935bd09aa
4 ficheiros alterados com 62 adições e 17 exclusões
  1. 12 5
      src/entt/core/family.hpp
  2. 37 12
      src/entt/core/ident.hpp
  3. 6 0
      test/entt/core/family.cpp
  4. 7 0
      test/entt/core/ident.cpp

+ 12 - 5
src/entt/core/family.hpp

@@ -4,7 +4,6 @@
 
 #include<type_traits>
 #include<cstddef>
-#include<utility>
 
 
 namespace entt {
@@ -24,15 +23,23 @@ class Family {
         return value++;
     }
 
+    template<typename...>
+    static std::size_t family() noexcept {
+        static const std::size_t value = identifier();
+        return value;
+    }
+
 public:
+    /*! @brief Unsigned integer type. */
+    using family_type = std::size_t;
+
     /**
      * @brief Returns an unique identifier for the given type.
      * @return Statically generated unique identifier for the given type.
      */
-    template<typename...>
-    static std::size_t type() noexcept {
-        static const std::size_t value = identifier();
-        return value;
+    template<typename... Type>
+    static family_type type() noexcept {
+        return family<std::decay_t<Type>...>();
     }
 };
 

+ 37 - 12
src/entt/core/ident.hpp

@@ -13,21 +13,37 @@ namespace entt {
 namespace {
 
 
-template<typename Type>
-struct Wrapper {
-    using type = Type;
-    constexpr Wrapper(std::size_t index): index{index} {}
-    const std::size_t index;
-};
-
-
 template<typename... Types>
-struct Identifier final: Wrapper<Types>... {
+struct Identifier final: Identifier<Types>... {
+    using identifier_type = std::size_t;
+
     template<std::size_t... Indexes>
-    constexpr Identifier(std::index_sequence<Indexes...>): Wrapper<Types>{Indexes}... {}
+    constexpr Identifier(std::index_sequence<Indexes...>)
+        : Identifier<Types>{std::index_sequence<Indexes>{}}...
+    {}
 
     template<typename Type>
-    constexpr std::size_t get() const { return Wrapper<std::decay_t<Type>>::index; }
+    constexpr std::size_t get() const {
+        return Identifier<std::decay_t<Type>>::get();
+    }
+};
+
+
+template<typename Type>
+struct Identifier<Type> {
+    using identifier_type = std::size_t;
+
+    template<std::size_t Index>
+    constexpr Identifier(std::index_sequence<Index>)
+        : index{Index}
+    {}
+
+    constexpr std::size_t get() const {
+        return index;
+    }
+
+private:
+    const std::size_t index;
 };
 
 
@@ -59,7 +75,16 @@ struct Identifier final: Wrapper<Types>... {
  * }
  * @endcode
  *
- * @tparam Types The list of types for which to generate identifiers.
+ * @note
+ * In case of single type list, `get` isn't a member function template:
+ * @code{.cpp}
+ * func(std::integral_constant<
+ *     entt::ident<AType>::identifier_type,
+ *     entt::ident<AType>::get()
+ * >{});
+ * @endcode
+ *
+ * @tparam Types List of types for which to generate identifiers.
  */
 template<typename... Types>
 constexpr auto ident = Identifier<std::decay_t<Types>...>{std::make_index_sequence<sizeof...(Types)>{}};

+ 6 - 0
test/entt/core/family.cpp

@@ -14,3 +14,9 @@ TEST(Family, Functionalities) {
     ASSERT_NE(myFamilyType, myOtherFamilyType);
     ASSERT_EQ(myFamilyType, yourFamilyType);
 }
+
+TEST(Family, Uniqueness) {
+    ASSERT_EQ(my_family::type<int>(), my_family::type<int &>());
+    ASSERT_EQ(my_family::type<int>(), my_family::type<int &&>());
+    ASSERT_EQ(my_family::type<int>(), my_family::type<const int &>());
+}

+ 7 - 0
test/entt/core/ident.cpp

@@ -1,3 +1,4 @@
+#include <type_traits>
 #include <gtest/gtest.h>
 #include <entt/core/ident.hpp>
 
@@ -24,3 +25,9 @@ TEST(Identifier, Uniqueness) {
         SUCCEED();
     }
 }
+
+TEST(Identifier, SingleType) {
+    constexpr auto ID = entt::ident<A>;
+    std::integral_constant<decltype(ID)::identifier_type, ID.get()> ic;
+    (void)ic;
+}