Browse Source

any: added ::reset

Michele Caini 5 years ago
parent
commit
a045c88c61
2 changed files with 17 additions and 0 deletions
  1. 5 0
      src/entt/core/any.hpp
  2. 12 0
      test/entt/core/any.cpp

+ 5 - 0
src/entt/core/any.hpp

@@ -266,6 +266,11 @@ public:
         *this = any{std::in_place_type<Type>, std::forward<Args>(args)...};
     }
 
+    /*! @brief Destroys contained object */
+    void reset() {
+       emplace<void>();
+    }
+
     /**
      * @brief Returns false if a wrapper is empty, true otherwise.
      * @return False if the wrapper is empty, true otherwise.

+ 12 - 0
test/entt/core/any.cpp

@@ -462,6 +462,18 @@ TEST(Any, EmplaceVoid) {
     ASSERT_FALSE(any.type());
  }
 
+TEST(Any, Reset) {
+    entt::any any{42};
+
+    ASSERT_TRUE(any);
+    ASSERT_EQ(any.type(), entt::type_id<int>());
+
+    any.reset();
+
+    ASSERT_FALSE(any);
+    ASSERT_EQ(any.type(), entt::type_info{});
+}
+
 TEST(Any, SBOSwap) {
     entt::any lhs{'c'};
     entt::any rhs{42};