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 Dec 2, 2024
1 parent a88a48d commit b58ba95
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 b58ba95

Please sign in to comment.