enable to get toml::value as toml::value

This commit is contained in:
ToruNiina 2018-12-16 20:50:40 +09:00
parent 0c08b9e940
commit c2e733a65d
2 changed files with 32 additions and 0 deletions

View File

@ -116,6 +116,14 @@ BOOST_AUTO_TEST_CASE(test_get_exact)
tab["key3"] = toml::value(123);
BOOST_CHECK(tab == toml::get<toml::table>(v));
}
{
toml::value v1(42);
BOOST_CHECK(v1 == toml::get<toml::value>(v1));
toml::value v2(54);
toml::get<toml::value>(v1) = v2;
BOOST_CHECK(v2 == toml::get<toml::table>(v1));
}
}
BOOST_AUTO_TEST_CASE(test_get_integer_type)

View File

@ -33,6 +33,30 @@ inline T&& get(value&& v)
return std::move(v.cast<detail::toml_value_t<T>::value>());
}
// ============================================================================
// T == toml::value; identity transformation.
template<typename T, typename std::enable_if<
std::is_same<T, ::toml::value>::value, std::nullptr_t>::type = nullptr>
inline T& get(value& v)
{
return v;
}
template<typename T, typename std::enable_if<
std::is_same<T, ::toml::value>::value, std::nullptr_t>::type = nullptr>
inline T const& get(const value& v)
{
return v;
}
template<typename T, typename std::enable_if<
std::is_same<T, ::toml::value>::value, std::nullptr_t>::type = nullptr>
inline T&& get(value&& v)
{
return std::move(v);
}
// ============================================================================
// integer convertible from toml::Integer