mirror of
https://github.com/ToruNiina/toml11.git
synced 2025-09-18 02:08:09 +08:00
feat(#156): add find_or(value, keys..., opt)
This commit is contained in:
18
toml/get.hpp
18
toml/get.hpp
@@ -1033,6 +1033,24 @@ find_or(const basic_value<C, M, V>& v, const toml::key& ky, T&& opt)
|
||||
return get_or(tab.at(ky), std::forward<T>(opt));
|
||||
}
|
||||
|
||||
template<typename T, typename C,
|
||||
template<typename ...> class M, template<typename ...> class V,
|
||||
typename ... Ks>
|
||||
auto find_or(const basic_value<C, M, V>& v, const toml::key& ky, Ks&& ... keys)
|
||||
-> decltype(find_or<T>(v, ky, detail::last_one(std::forward<Ks>(keys)...)))
|
||||
{
|
||||
if(!v.is_table())
|
||||
{
|
||||
return detail::last_one(std::forward<Ks>(keys)...);
|
||||
}
|
||||
const auto& tab = v.as_table();
|
||||
if(tab.count(ky) == 0)
|
||||
{
|
||||
return detail::last_one(std::forward<Ks>(keys)...);
|
||||
}
|
||||
return find_or(tab.at(ky), std::forward<Ks>(keys)...);
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// expect
|
||||
|
||||
|
Reference in New Issue
Block a user