From a045c88c6181bf87719bda695653cc98bd4a207e Mon Sep 17 00:00:00 2001 From: Michele Caini Date: Sat, 23 Jan 2021 18:04:03 +0100 Subject: [PATCH] any: added ::reset --- src/entt/core/any.hpp | 5 +++++ test/entt/core/any.cpp | 12 ++++++++++++ 2 files changed, 17 insertions(+) diff --git a/src/entt/core/any.hpp b/src/entt/core/any.hpp index 3d273cc33..8d4273ad7 100644 --- a/src/entt/core/any.hpp +++ b/src/entt/core/any.hpp @@ -266,6 +266,11 @@ public: *this = any{std::in_place_type, std::forward(args)...}; } + /*! @brief Destroys contained object */ + void reset() { + emplace(); + } + /** * @brief Returns false if a wrapper is empty, true otherwise. * @return False if the wrapper is empty, true otherwise. diff --git a/test/entt/core/any.cpp b/test/entt/core/any.cpp index f2a03b52c..a213cd3d2 100644 --- a/test/entt/core/any.cpp +++ b/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()); + + any.reset(); + + ASSERT_FALSE(any); + ASSERT_EQ(any.type(), entt::type_info{}); +} + TEST(Any, SBOSwap) { entt::any lhs{'c'}; entt::any rhs{42};