mirror of
https://github.com/ToruNiina/toml11.git
synced 2025-12-16 03:08:52 +08:00
Compare commits
3 Commits
v4.4.0
...
fix-overlo
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0d1a52c3db | ||
|
|
89b376b4df | ||
|
|
37262bbbbe |
@@ -17,21 +17,24 @@ namespace toml
|
|||||||
// find<T>(value, key);
|
// find<T>(value, key);
|
||||||
|
|
||||||
template<typename T, typename TC>
|
template<typename T, typename TC>
|
||||||
decltype(::toml::get<T>(std::declval<basic_value<TC> const&>()))
|
cxx::enable_if_t<cxx::negation<detail::is_std_optional<T>>::value,
|
||||||
|
decltype(::toml::get<T>(std::declval<basic_value<TC> const&>()))>
|
||||||
find(const basic_value<TC>& v, const typename basic_value<TC>::key_type& ky)
|
find(const basic_value<TC>& v, const typename basic_value<TC>::key_type& ky)
|
||||||
{
|
{
|
||||||
return ::toml::get<T>(v.at(ky));
|
return ::toml::get<T>(v.at(ky));
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T, typename TC>
|
template<typename T, typename TC>
|
||||||
decltype(::toml::get<T>(std::declval<basic_value<TC>&>()))
|
cxx::enable_if_t<cxx::negation<detail::is_std_optional<T>>::value,
|
||||||
|
decltype(::toml::get<T>(std::declval<basic_value<TC>&>()))>
|
||||||
find(basic_value<TC>& v, const typename basic_value<TC>::key_type& ky)
|
find(basic_value<TC>& v, const typename basic_value<TC>::key_type& ky)
|
||||||
{
|
{
|
||||||
return ::toml::get<T>(v.at(ky));
|
return ::toml::get<T>(v.at(ky));
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T, typename TC>
|
template<typename T, typename TC>
|
||||||
decltype(::toml::get<T>(std::declval<basic_value<TC>&&>()))
|
cxx::enable_if_t<cxx::negation<detail::is_std_optional<T>>::value,
|
||||||
|
decltype(::toml::get<T>(std::declval<basic_value<TC>&&>()))>
|
||||||
find(basic_value<TC>&& v, const typename basic_value<TC>::key_type& ky)
|
find(basic_value<TC>&& v, const typename basic_value<TC>::key_type& ky)
|
||||||
{
|
{
|
||||||
return ::toml::get<T>(std::move(v.at(ky)));
|
return ::toml::get<T>(std::move(v.at(ky)));
|
||||||
@@ -41,19 +44,22 @@ find(basic_value<TC>&& v, const typename basic_value<TC>::key_type& ky)
|
|||||||
// find<T>(value, idx)
|
// find<T>(value, idx)
|
||||||
|
|
||||||
template<typename T, typename TC>
|
template<typename T, typename TC>
|
||||||
decltype(::toml::get<T>(std::declval<basic_value<TC> const&>()))
|
cxx::enable_if_t<cxx::negation<detail::is_std_optional<T>>::value,
|
||||||
|
decltype(::toml::get<T>(std::declval<basic_value<TC> const&>()))>
|
||||||
find(const basic_value<TC>& v, const std::size_t idx)
|
find(const basic_value<TC>& v, const std::size_t idx)
|
||||||
{
|
{
|
||||||
return ::toml::get<T>(v.at(idx));
|
return ::toml::get<T>(v.at(idx));
|
||||||
}
|
}
|
||||||
template<typename T, typename TC>
|
template<typename T, typename TC>
|
||||||
decltype(::toml::get<T>(std::declval<basic_value<TC>&>()))
|
cxx::enable_if_t<cxx::negation<detail::is_std_optional<T>>::value,
|
||||||
|
decltype(::toml::get<T>(std::declval<basic_value<TC>&>()))>
|
||||||
find(basic_value<TC>& v, const std::size_t idx)
|
find(basic_value<TC>& v, const std::size_t idx)
|
||||||
{
|
{
|
||||||
return ::toml::get<T>(v.at(idx));
|
return ::toml::get<T>(v.at(idx));
|
||||||
}
|
}
|
||||||
template<typename T, typename TC>
|
template<typename T, typename TC>
|
||||||
decltype(::toml::get<T>(std::declval<basic_value<TC>&&>()))
|
cxx::enable_if_t<cxx::negation<detail::is_std_optional<T>>::value,
|
||||||
|
decltype(::toml::get<T>(std::declval<basic_value<TC>&&>()))>
|
||||||
find(basic_value<TC>&& v, const std::size_t idx)
|
find(basic_value<TC>&& v, const std::size_t idx)
|
||||||
{
|
{
|
||||||
return ::toml::get<T>(std::move(v.at(idx)));
|
return ::toml::get<T>(std::move(v.at(idx)));
|
||||||
@@ -262,19 +268,22 @@ find(basic_value<TC>&& v, const K1& k1, const K2& k2, const Ks& ... ks)
|
|||||||
// find<T>(v, keys...)
|
// find<T>(v, keys...)
|
||||||
|
|
||||||
template<typename T, typename TC, typename K1, typename K2, typename ... Ks>
|
template<typename T, typename TC, typename K1, typename K2, typename ... Ks>
|
||||||
decltype(::toml::get<T>(std::declval<const basic_value<TC>&>()))
|
cxx::enable_if_t<cxx::negation<detail::is_std_optional<T>>::value,
|
||||||
|
decltype(::toml::get<T>(std::declval<const basic_value<TC>&>()))>
|
||||||
find(const basic_value<TC>& v, const K1& k1, const K2& k2, const Ks& ... ks)
|
find(const basic_value<TC>& v, const K1& k1, const K2& k2, const Ks& ... ks)
|
||||||
{
|
{
|
||||||
return find<T>(v.at(detail::key_cast<TC>(k1)), detail::key_cast<TC>(k2), ks...);
|
return find<T>(v.at(detail::key_cast<TC>(k1)), detail::key_cast<TC>(k2), ks...);
|
||||||
}
|
}
|
||||||
template<typename T, typename TC, typename K1, typename K2, typename ... Ks>
|
template<typename T, typename TC, typename K1, typename K2, typename ... Ks>
|
||||||
decltype(::toml::get<T>(std::declval<basic_value<TC>&>()))
|
cxx::enable_if_t<cxx::negation<detail::is_std_optional<T>>::value,
|
||||||
|
decltype(::toml::get<T>(std::declval<basic_value<TC>&>()))>
|
||||||
find(basic_value<TC>& v, const K1& k1, const K2& k2, const Ks& ... ks)
|
find(basic_value<TC>& v, const K1& k1, const K2& k2, const Ks& ... ks)
|
||||||
{
|
{
|
||||||
return find<T>(v.at(detail::key_cast<TC>(k1)), detail::key_cast<TC>(k2), ks...);
|
return find<T>(v.at(detail::key_cast<TC>(k1)), detail::key_cast<TC>(k2), ks...);
|
||||||
}
|
}
|
||||||
template<typename T, typename TC, typename K1, typename K2, typename ... Ks>
|
template<typename T, typename TC, typename K1, typename K2, typename ... Ks>
|
||||||
decltype(::toml::get<T>(std::declval<basic_value<TC>&&>()))
|
cxx::enable_if_t<cxx::negation<detail::is_std_optional<T>>::value,
|
||||||
|
decltype(::toml::get<T>(std::declval<basic_value<TC>&&>()))>
|
||||||
find(basic_value<TC>&& v, const K1& k1, const K2& k2, const Ks& ... ks)
|
find(basic_value<TC>&& v, const K1& k1, const K2& k2, const Ks& ... ks)
|
||||||
{
|
{
|
||||||
return find<T>(std::move(v.at(detail::key_cast<TC>(k1))), detail::key_cast<TC>(k2), ks...);
|
return find<T>(std::move(v.at(detail::key_cast<TC>(k1))), detail::key_cast<TC>(k2), ks...);
|
||||||
|
|||||||
@@ -165,14 +165,14 @@ struct is_std_tuple_impl<std::tuple<Ts...>> : std::true_type{};
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
using is_std_tuple = is_std_tuple_impl<cxx::remove_cvref_t<T>>;
|
using is_std_tuple = is_std_tuple_impl<cxx::remove_cvref_t<T>>;
|
||||||
|
|
||||||
#if TOML11_CPLUSPLUS_STANDARD_VERSION >= TOML11_CXX17_VALUE
|
#if defined(TOML11_HAS_OPTIONAL)
|
||||||
# if __has_include(<optional>)
|
|
||||||
template<typename T> struct is_std_optional_impl : std::false_type{};
|
template<typename T> struct is_std_optional_impl : std::false_type{};
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct is_std_optional_impl<std::optional<T>> : std::true_type{};
|
struct is_std_optional_impl<std::optional<T>> : std::true_type{};
|
||||||
template<typename T>
|
template<typename T>
|
||||||
using is_std_optional = is_std_optional_impl<cxx::remove_cvref_t<T>>;
|
using is_std_optional = is_std_optional_impl<cxx::remove_cvref_t<T>>;
|
||||||
# endif // <optional>
|
#else
|
||||||
|
template<typename T> struct is_std_optional : std::false_type{};
|
||||||
#endif // > C++17
|
#endif // > C++17
|
||||||
|
|
||||||
template<typename T> struct is_std_array_impl : std::false_type{};
|
template<typename T> struct is_std_array_impl : std::false_type{};
|
||||||
@@ -211,6 +211,11 @@ template<typename V, typename S>
|
|||||||
struct is_string_view_of : std::false_type {};
|
struct is_string_view_of : std::false_type {};
|
||||||
template<typename C, typename T>
|
template<typename C, typename T>
|
||||||
struct is_string_view_of<std::basic_string_view<C, T>, std::basic_string<C, T>> : std::true_type {};
|
struct is_string_view_of<std::basic_string_view<C, T>, std::basic_string<C, T>> : std::true_type {};
|
||||||
|
#else
|
||||||
|
template<typename T>
|
||||||
|
struct is_std_basic_string_view : std::false_type {};
|
||||||
|
template<typename V, typename S>
|
||||||
|
struct is_string_view_of : std::false_type {};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
template<typename T> struct is_chrono_duration_impl: std::false_type{};
|
template<typename T> struct is_chrono_duration_impl: std::false_type{};
|
||||||
|
|||||||
@@ -735,5 +735,27 @@ TEST_CASE("test_optional_conversion_via_macro")
|
|||||||
CHECK(v2 == v);
|
CHECK(v2 == v);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_CASE("test_optional_conversion_via_find")
|
||||||
|
{
|
||||||
|
{
|
||||||
|
const toml::value v(toml::table{
|
||||||
|
{"foo", toml::value(toml::table{{"a", 42}}) }
|
||||||
|
});
|
||||||
|
|
||||||
|
const auto foo = toml::find<extlib4::foo>(v, "foo");
|
||||||
|
CHECK(foo.a.value() == 42);
|
||||||
|
CHECK(foo.b == std::nullopt);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
const toml::ordered_value v(toml::ordered_table{
|
||||||
|
{ "foo", toml::ordered_value(toml::ordered_table{{"b", "baz"}}) }
|
||||||
|
});
|
||||||
|
|
||||||
|
const auto foo = toml::find<extlib4::foo>(v, "foo");
|
||||||
|
CHECK(foo.a == std::nullopt);
|
||||||
|
CHECK(foo.b.value() == "baz");
|
||||||
|
}
|
||||||
|
}
|
||||||
#endif // TOML11_HAS_OPTIONAL
|
#endif // TOML11_HAS_OPTIONAL
|
||||||
#endif // TOML11_WITHOUT_DEFINE_NON_INTRUSIVE
|
#endif // TOML11_WITHOUT_DEFINE_NON_INTRUSIVE
|
||||||
|
|||||||
Reference in New Issue
Block a user