Fixed etl::expected in-place constructors

This commit is contained in:
John Wellbelove 2025-01-22 14:50:42 +00:00
parent 20ef1a34fc
commit efa7c19e8b
2 changed files with 35 additions and 2 deletions

View File

@ -350,7 +350,7 @@ namespace etl
//*******************************************
template <typename... Args>
ETL_CONSTEXPR14 explicit expected(etl::in_place_t, Args&&... args)
: storage(etl::forward<Args>(args)...)
: storage(etl::in_place_index_t<Value_Type>(), etl::forward<Args>(args)...)
{
}
@ -360,7 +360,7 @@ namespace etl
//*******************************************
template <typename U, typename... Args>
ETL_CONSTEXPR14 explicit expected(etl::in_place_t, std::initializer_list<U> il, Args&&... args)
: storage(il, etl::forward<Args>(args)...)
: storage(etl::in_place_index_t<Value_Type>(), il, etl::forward<Args>(args)...)
{
}
#endif

View File

@ -161,6 +161,39 @@ namespace
CHECK_TRUE(output.v == input.v);
}
//*************************************************************************
TEST(test_constructor_in_place_result_with_value)
{
struct ValueInPlace
{
ValueInPlace()
: a(0)
, b(0)
{
}
ValueInPlace(int a_, int b_)
: a(a_)
, b(b_)
{
}
int a;
int b;
};
using ExpectedInPlace = etl::expected<ValueInPlace, Error>;
ExpectedInPlace expected(etl::in_place, 1, 2);
ValueInPlace output = expected.value();
CHECK_TRUE(expected.has_value());
CHECK_TRUE(bool(expected));
CHECK_TRUE(output.a == 1);
CHECK_TRUE(output.b == 2);
}
//*************************************************************************
TEST(test_constructor_for_const_result_with_value)
{