Ver Fonte

monostate: helper template variable

Michele Caini há 7 anos atrás
pai
commit
8212ed6d87
3 ficheiros alterados com 10 adições e 3 exclusões
  1. 0 1
      TODO
  2. 8 0
      src/entt/core/monostate.hpp
  3. 2 2
      test/entt/core/monostate.cpp

+ 0 - 1
TODO

@@ -21,7 +21,6 @@
 * write/show how to create an archetype based model on top of EnTT
 * mention hunter in the readme file, section packaging tools
 * monostate: make constraint trivially copyable due to atomic optional
-* monostate: use template variable to avoid {}
 * travis + windows is now available, try it
 * events on replace, so that one can track updated components? indagate impact
 * allow to bind values to delegate on connect with free functions (sbo + check size on costruction to guarantee a zero allocation abstraction)

+ 8 - 0
src/entt/core/monostate.hpp

@@ -49,6 +49,14 @@ private:
 };
 
 
+/**
+ * @brief Helper variable template.
+ * @tparam Value Value used to differentiate between different variables.
+ */
+template<hashed_string::hash_type Value>
+inline monostate<Value> monostate_v = {};
+
+
 }
 
 

+ 2 - 2
test/entt/core/monostate.cpp

@@ -10,10 +10,10 @@ TEST(Monostate, Functionalities) {
     ASSERT_EQ(i_pre, int{});
 
     entt::monostate<"foobar"_hs>{} = true;
-    entt::monostate<"foobar"_hs>{} = 42;
+    entt::monostate_v<"foobar"_hs> = 42;
 
     const bool &b_post = entt::monostate<"foobar"_hs>{};
-    const int &i_post = entt::monostate<entt::hashed_string{"foobar"}>{};
+    const int &i_post = entt::monostate_v<entt::hashed_string{"foobar"}>;
 
     ASSERT_TRUE(b_post);
     ASSERT_EQ(i_post, 42);