diff --git a/single_include/toml.hpp b/single_include/toml.hpp index 4bdda545..2658c2e0 100644 --- a/single_include/toml.hpp +++ b/single_include/toml.hpp @@ -9671,6 +9671,37 @@ T find_or(const basic_value& v, const K1& k1, const K2& k2, const K3& k3, co } } +// =========================================================================== +// find_or_default(value, key) + +template +cxx::enable_if_t::value, T> +find_or_default(const basic_value& v, K&& k) noexcept(std::is_nothrow_default_constructible::value) +{ + try + { + return ::toml::get(v.at(detail::key_cast(std::forward(k)))); + } + catch(...) + { + return T(); + } +} + +template +cxx::enable_if_t::value, T> +find_or_default(const basic_value& v, K1&& k1, Ks&& ... keys) noexcept(std::is_nothrow_default_constructible::value) +{ + try + { + return find_or_default(v.at(std::forward(k1)), std::forward(keys)...); + } + catch(...) + { + return T(); + } +} + } // toml #endif // TOML11_FIND_HPP #ifndef TOML11_CONVERSION_HPP