mirror of
https://github.com/ToruNiina/toml11.git
synced 2025-09-17 17:58:09 +08:00
add temporary to receive rvalue
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user