From c87bdaaeeae869d78cf30a0f19dd6c8db4b5b2b2 Mon Sep 17 00:00:00 2001 From: ToruNiina Date: Sat, 18 Jan 2025 08:23:45 +0000 Subject: [PATCH] feat [skip ci]: update single_include --- single_include/toml.hpp | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/single_include/toml.hpp b/single_include/toml.hpp index 4bdda54..2658c2e 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