Skip to content

Commit

Permalink
Merge branch 'pull-request/#982-Added-return-to-etl-optional-emplace-…
Browse files Browse the repository at this point in the history
…fixed-typo' into development
  • Loading branch information
jwellbelove committed Dec 2, 2024
2 parents 1b76d93 + b58ba95 commit 3a5b552
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 3a5b552

Please sign in to comment.