diff --git a/include/etl/expected.h b/include/etl/expected.h index 0dc4a584..d73fd6f8 100644 --- a/include/etl/expected.h +++ b/include/etl/expected.h @@ -350,7 +350,7 @@ namespace etl //******************************************* template ETL_CONSTEXPR14 explicit expected(etl::in_place_t, Args&&... args) - : storage(etl::forward(args)...) + : storage(etl::in_place_index_t(), etl::forward(args)...) { } @@ -360,7 +360,7 @@ namespace etl //******************************************* template ETL_CONSTEXPR14 explicit expected(etl::in_place_t, std::initializer_list il, Args&&... args) - : storage(il, etl::forward(args)...) + : storage(etl::in_place_index_t(), il, etl::forward(args)...) { } #endif diff --git a/test/test_expected.cpp b/test/test_expected.cpp index 11f2d8b3..ddd686f9 100644 --- a/test/test_expected.cpp +++ b/test/test_expected.cpp @@ -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; + + 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) {