Skip to content

Commit

Permalink
Added return to etl::optional emplace, fixed typo (#982)
Browse files Browse the repository at this point in the history
  • Loading branch information
rolandreichweinbmw authored and jwellbelove committed Dec 19, 2024
1 parent 9ed9b90 commit cd1805b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
12 changes: 8 additions & 4 deletions include/etl/optional.h
Original file line number Diff line number Diff line change
Expand Up @@ -484,14 +484,16 @@ namespace etl
//*************************************************************************
template <typename... TArgs>
ETL_CONSTEXPR20_STL
void emplace(TArgs&& ... args)
T& emplace(TArgs&& ... args)
{
storage.construct(etl::forward<TArgs>(args)...);

return storage.u.value;
}
#else
//*************************************************************************
/// Emplaces a value.
/// 1 parameter.
/// 0 parameters.
//*************************************************************************
T& emplace()
{
Expand Down Expand Up @@ -1048,14 +1050,16 @@ namespace etl
//*************************************************************************
template <typename... TArgs>
ETL_CONSTEXPR14
void emplace(TArgs&& ... args)
T& emplace(TArgs&& ... args)
{
storage.construct(etl::forward<TArgs>(args)...);

return storage.value;
}
#else
//*************************************************************************
/// Emplaces a value.
/// 1 parameter.
/// 0 parameters.
//*************************************************************************
T& emplace()
{
Expand Down
10 changes: 10 additions & 0 deletions test/test_optional.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,16 @@ namespace
CHECK_EQUAL(0, int(result.value()));
}

//*************************************************************************
TEST(test_emplace_return)
{
etl::optional<DataM> data;

DataM* datam = &data.emplace(1U);
CHECK_EQUAL(datam, &data.value());
CHECK(datam != nullptr);
}

//*************************************************************************
TEST(test_moveable)
{
Expand Down

0 comments on commit cd1805b

Please sign in to comment.