any: added ::reset

This commit is contained in:
Michele Caini
2021-01-23 18:04:03 +01:00
parent a5fdf917df
commit a045c88c61
2 changed files with 17 additions and 0 deletions

View File

@@ -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.

View File

@@ -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};