mirror of
https://github.com/ToruNiina/toml11.git
synced 2025-09-18 10:28:09 +08:00
fix result::unwrap_or with rvalue ref; merge branch 'hotfix'
This commit is contained in:
@@ -68,9 +68,14 @@ BOOST_AUTO_TEST_CASE(test_expect)
|
|||||||
{
|
{
|
||||||
toml::value v1(42);
|
toml::value v1(42);
|
||||||
toml::value v2(3.14);
|
toml::value v2(3.14);
|
||||||
BOOST_CHECK_EQUAL(42, toml::expect<int>(v1).unwrap_or(0));
|
const auto v1_or_0 = toml::expect<int>(v1).unwrap_or(0);
|
||||||
BOOST_CHECK_EQUAL( 0, toml::expect<int>(v2).unwrap_or(0));
|
const auto v2_or_0 = toml::expect<int>(v2).unwrap_or(0);
|
||||||
BOOST_CHECK_EQUAL("42", toml::expect<int>(v1).map([](int i){return std::to_string(i);}).unwrap_or(std::string("none")));
|
BOOST_CHECK_EQUAL(42, v1_or_0);
|
||||||
BOOST_CHECK_EQUAL("none", toml::expect<int>(v2).map([](int i){return std::to_string(i);}).unwrap_or(std::string("none")));
|
BOOST_CHECK_EQUAL( 0, v2_or_0);
|
||||||
|
|
||||||
|
const auto v1_or_none = toml::expect<int>(v1).map([](int i){return std::to_string(i);}).unwrap_or(std::string("none"));
|
||||||
|
const auto v2_or_none = toml::expect<int>(v2).map([](int i){return std::to_string(i);}).unwrap_or(std::string("none"));
|
||||||
|
BOOST_CHECK_EQUAL("42", v1_or_none);
|
||||||
|
BOOST_CHECK_EQUAL("none", v2_or_none);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -406,10 +406,10 @@ struct result
|
|||||||
if(is_err()) {return opt;}
|
if(is_err()) {return opt;}
|
||||||
return this->succ.value;
|
return this->succ.value;
|
||||||
}
|
}
|
||||||
value_type&& unwrap_or(value_type opt) &&
|
value_type unwrap_or(value_type opt) &&
|
||||||
{
|
{
|
||||||
if(is_err()) {return std::move(opt);}
|
if(is_err()) {return opt;}
|
||||||
return std::move(this->succ.value);
|
return this->succ.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
error_type& unwrap_err() &
|
error_type& unwrap_err() &
|
||||||
|
Reference in New Issue
Block a user