mirror of
https://github.com/ETLCPP/etl.git
synced 2026-10-28 18:07:10 +08:00
Fix value_or not taking const in optional (#1225)
This commit is contained in:
parent
e5dd953c8b
commit
78f04ad298
@ -471,7 +471,7 @@ namespace etl
|
||||
etl::enable_if_t<etl::is_convertible<U, T>::value, T>
|
||||
value_or(U&& default_value) const&
|
||||
{
|
||||
return has_value() ? value() : etl::forward<T>(default_value);
|
||||
return has_value() ? value() : static_cast<T>(etl::forward<U>(default_value));
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
@ -482,7 +482,7 @@ namespace etl
|
||||
etl::enable_if_t<etl::is_convertible<U, T>::value, T>
|
||||
value_or(U&& default_value)&&
|
||||
{
|
||||
return has_value() ? etl::move(value()) : etl::forward<T>(default_value);
|
||||
return has_value() ? etl::move(value()) : static_cast<T>(etl::forward<U>(default_value));
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -1085,7 +1085,7 @@ namespace etl
|
||||
etl::enable_if_t<etl::is_convertible<U, T>::value, T>
|
||||
value_or(U&& default_value) const&
|
||||
{
|
||||
return has_value() ? value() : etl::forward<T>(default_value);
|
||||
return has_value() ? value() : static_cast<T>(etl::forward<U>(default_value));
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
@ -1096,7 +1096,7 @@ namespace etl
|
||||
etl::enable_if_t<etl::is_convertible<U, T>::value, T>
|
||||
value_or(U&& default_value)&&
|
||||
{
|
||||
return has_value() ? etl::move(value()) : etl::forward<T>(default_value);
|
||||
return has_value() ? etl::move(value()) : static_cast<T>(etl::forward<U>(default_value));
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@ -298,6 +298,21 @@ namespace
|
||||
CHECK_EQUAL(Data("Value"), result);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_value_or_const)
|
||||
{
|
||||
using FundamentalType = int;
|
||||
using NonFundamentalType = std::string;
|
||||
|
||||
const FundamentalType constFT{ 5 };
|
||||
int resultFT = etl::optional<FundamentalType>{}.value_or(constFT);
|
||||
CHECK_EQUAL(5, resultFT);
|
||||
|
||||
const NonFundamentalType constNFT{ "Default" };
|
||||
NonFundamentalType resultNFT = etl::optional<NonFundamentalType>{}.value_or(constNFT);
|
||||
CHECK_EQUAL("Default", resultNFT);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
struct github_bug_720_bug_helper
|
||||
{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user