Explorar o código

type traits: added is_complete[_v]

Michele Caini %!s(int64=5) %!d(string=hai) anos
pai
achega
315b1f5913
Modificáronse 3 ficheiros con 33 adicións e 5 borrados
  1. 5 2
      TODO
  2. 23 3
      src/entt/core/type_traits.hpp
  3. 5 0
      test/entt/core/type_traits.cpp

+ 5 - 2
TODO

@@ -14,17 +14,20 @@
   - enable/disable component
   - spatial query
   - runtime types pool
+  - off-line/off-memory/remote
+  - poly
   - ...
 
 WIP:
+* HP: headless view
 * HP: inject the registry to pools rather than passing it every time (fake vtable prep)
 * HP: fake vtable, see dino:: for a reasonable and customizable (pay-per-use) approach
 * HP: meta any/meta container: reduce instantiations with a single function fake vtable
+* HP: make view pack work also with groups, make packs input iterator only, add view adapter for external sources
+* HP: write documentation for custom storages and views!!
 * suppress warnings in meta.hpp (uninitialized members)
-* make view pack work also with groups, add multi-type iterator (not only input iterators)
 * add exclude-only views to combine with packs
 * deprecate non-owning groups in favor of owning views and view packs, introduce lazy owning views
-* HP: write documentation for custom storages and views!!
 * view pack: plain function as an alias for operator|, reverse iterators, rbegin and rend
 * what about using hashed string rather than hash values for meta types?
 * pagination doesn't work nicely across boundaries probably, give it a look. RO operations are fine, adding components maybe not.

+ 23 - 3
src/entt/core/type_traits.hpp

@@ -303,15 +303,35 @@ template<typename Ret, typename Func, typename Args>
 inline constexpr auto is_applicable_r_v = is_applicable_r<Ret, Func, Args>::value;
 
 
+/**
+* @brief Provides the member constant `value` to true if a given type is
+* complete, false otherwise.
+* @tparam Type Potential complete type.
+*/
+template<typename Type, typename = void>
+struct is_complete: std::false_type {};
+
+
+/*! @copydoc is_complete */
+template<typename Type>
+struct is_complete<Type, std::void_t<decltype(sizeof(Type))>>: std::true_type {};
+
+
+/**
+* @brief Helper variable template.
+* @tparam Type Potential complete type.
+*/
+template<typename Type>
+inline constexpr auto is_complete_v = is_complete<Type>::value;
+
+
 /**
  * @brief Provides the member constant `value` to true if a given type is empty
  * and the empty type optimization is enabled, false otherwise.
  * @tparam Type Potential empty type.
  */
 template<typename Type, typename = void>
-struct is_empty
-    : ENTT_IS_EMPTY(Type)
-{};
+struct is_empty: ENTT_IS_EMPTY(Type) {};
 
 
 /**

+ 5 - 0
test/entt/core/type_traits.cpp

@@ -70,6 +70,11 @@ TEST(TypeTraits, IsApplicable) {
     static_assert(!entt::is_applicable_r_v<int, int(int, char), std::tuple<void>>);
 }
 
+TEST(TypeTraits, IsComplete) {
+    static_assert(entt::is_complete_v<int>);
+    static_assert(!entt::is_complete_v<void>);
+}
+
 TEST(TypeTraits, ConstnessAs) {
     static_assert(std::is_same_v<entt::constness_as_t<int, char>, int>);
     static_assert(std::is_same_v<entt::constness_as_t<const int, char>, int>);