mirror of
https://github.com/ETLCPP/etl.git
synced 2026-04-30 19:09:10 +08:00
Fixed etl::expected in-place constructors
This commit is contained in:
parent
20ef1a34fc
commit
efa7c19e8b
@ -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
|
||||
|
||||
@ -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)
|
||||
{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user