diff --git a/include/etl/optional.h b/include/etl/optional.h index a1ec6a64..08cf7805 100644 --- a/include/etl/optional.h +++ b/include/etl/optional.h @@ -313,6 +313,18 @@ namespace etl other = temp; } + //*************************************************************************** + /// Reset back to invalid. + //*************************************************************************** + void reset() + { + if (valid) + { + storage.template get_reference().~T(); + valid = false; + } + } + private: typename etl::aligned_storage_as::type storage; diff --git a/support/Release notes.txt b/support/Release notes.txt index 1f55c588..58b72831 100644 --- a/support/Release notes.txt +++ b/support/Release notes.txt @@ -1,3 +1,7 @@ +=============================================================================== +11.00.1 +Added reset() to etl::optional + =============================================================================== 11.00.0 New directory structure. diff --git a/test/test_optional.cpp b/test/test_optional.cpp index e0d081f4..a8b2d665 100644 --- a/test/test_optional.cpp +++ b/test/test_optional.cpp @@ -396,5 +396,15 @@ namespace CHECK_EQUAL(data1, original2); CHECK_EQUAL(data2, original1); } + + //************************************************************************* + TEST(test_reset) + { + etl::optional data(Data("1")); + CHECK(bool(data)); + + data.reset(); + CHECK(!bool(data)); + } }; }