Procházet zdrojové kódy

poly: added ::reset

Michele Caini před 5 roky
rodič
revize
2822eda858

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

@@ -280,6 +280,11 @@ public:
         vtable = poly_vtable<Concept>::template instance<Type>();
     }
 
+    /*! @brief Destroys contained object */
+    void reset() {
+        *this = poly{};
+    }
+
     /**
      * @brief Returns false if a poly is empty, true otherwise.
      * @return False if the poly is empty, true otherwise.

+ 5 - 0
test/entt/poly/poly_deduced.cpp

@@ -99,6 +99,11 @@ TEST(PolyDeduced, Functionalities) {
     ASSERT_TRUE(move);
     ASSERT_FALSE(copy);
     ASSERT_EQ(move->get(), 3);
+
+    move.reset();
+
+    ASSERT_FALSE(move);
+    ASSERT_EQ(move.type(), entt::type_info{});
 }
 
 TEST(PolyDeduced, Owned) {

+ 5 - 0
test/entt/poly/poly_defined.cpp

@@ -105,6 +105,11 @@ TEST(PolyDefined, Functionalities) {
     ASSERT_TRUE(move);
     ASSERT_FALSE(copy);
     ASSERT_EQ(move->get(), 3);
+
+    move.reset();
+
+    ASSERT_FALSE(move);
+    ASSERT_EQ(move.type(), entt::type_info{});
 }
 
 TEST(PolyDefined, Owned) {