diff --git a/include/etl/optional.h b/include/etl/optional.h index 002d010a9..f70b2689c 100644 --- a/include/etl/optional.h +++ b/include/etl/optional.h @@ -484,14 +484,16 @@ namespace etl //************************************************************************* template ETL_CONSTEXPR20_STL - void emplace(TArgs&& ... args) + T& emplace(TArgs&& ... args) { storage.construct(etl::forward(args)...); + + return storage.u.value; } #else //************************************************************************* /// Emplaces a value. - /// 1 parameter. + /// 0 parameters. //************************************************************************* T& emplace() { @@ -1048,14 +1050,16 @@ namespace etl //************************************************************************* template ETL_CONSTEXPR14 - void emplace(TArgs&& ... args) + T& emplace(TArgs&& ... args) { storage.construct(etl::forward(args)...); + + return storage.value; } #else //************************************************************************* /// Emplaces a value. - /// 1 parameter. + /// 0 parameters. //************************************************************************* T& emplace() { diff --git a/test/test_optional.cpp b/test/test_optional.cpp index 61e68672b..87ee24c72 100644 --- a/test/test_optional.cpp +++ b/test/test_optional.cpp @@ -157,6 +157,16 @@ namespace CHECK_EQUAL(0, int(result.value())); } + //************************************************************************* + TEST(test_emplace_return) + { + etl::optional data; + + DataM* datam = &data.emplace(1U); + CHECK_EQUAL(datam, &data.value()); + CHECK(datam != nullptr); + } + //************************************************************************* TEST(test_moveable) {