Browse Source

meta: added meta_any::reset

Michele Caini 5 years ago
parent
commit
6c804b5ca2
2 changed files with 17 additions and 0 deletions
  1. 5 0
      src/entt/meta/meta.hpp
  2. 12 0
      test/entt/meta/meta_any.cpp

+ 5 - 0
src/entt/meta/meta.hpp

@@ -639,6 +639,11 @@ public:
         *this = meta_any{std::in_place_type<Type>, std::forward<Args>(args)...};
     }
 
+    /*! @brief Destroys contained object */
+    void reset() {
+        *this = meta_any{};
+    }
+
     /**
      * @brief Returns a sequence container proxy.
      * @return A sequence container proxy for the underlying object.

+ 12 - 0
test/entt/meta/meta_any.cpp

@@ -462,6 +462,18 @@ TEST_F(MetaAny, EmplaceVoid) {
     ASSERT_EQ(any, (entt::meta_any{std::in_place_type<void>}));
 }
 
+TEST_F(MetaAny, Reset) {
+    entt::meta_any any{42};
+
+    ASSERT_TRUE(any);
+    ASSERT_EQ(any.type(), entt::resolve<int>());
+
+    any.reset();
+
+    ASSERT_FALSE(any);
+    ASSERT_EQ(any.type(), entt::meta_type{});
+}
+
 TEST_F(MetaAny, SBOSwap) {
     entt::meta_any lhs{'c'};
     entt::meta_any rhs{42};