diff --git a/toml/get.hpp b/toml/get.hpp index 627f6aa..01dd7c2 100644 --- a/toml/get.hpp +++ b/toml/get.hpp @@ -549,17 +549,16 @@ find(basic_value&& v, const key& ky) return ::toml::get(std::move(tab.at(ky))); } -/* - // ============================================================================ // get_or(value, fallback) // ---------------------------------------------------------------------------- // specialization for the exact toml types (return type becomes lvalue ref) -template::value, std::nullptr_t>::type = nullptr> -T const& get_or(const toml::value& v, const T& opt) +template class M, template class V> +enable_if_t>::value, T> const& +get_or(const basic_value& v, const T& opt) { try { @@ -571,9 +570,10 @@ T const& get_or(const toml::value& v, const T& opt) return opt; } } -template::value, std::nullptr_t>::type = nullptr> -T& get_or(toml::value& v, T& opt) +template class M, template class V> +enable_if_t>::value, T>& +get_or(basic_value& v, T& opt) { try { @@ -585,9 +585,10 @@ T& get_or(toml::value& v, T& opt) return opt; } } -template::value, std::nullptr_t>::type = nullptr> -T&& get_or(toml::value&& v, T&& opt) +template class M, template class V> +enable_if_t>::value, T>&& +get_or(basic_value&& v, T&& opt) { try { @@ -603,53 +604,67 @@ T&& get_or(toml::value&& v, T&& opt) // ---------------------------------------------------------------------------- // specialization for std::string (return type becomes lvalue ref) -template::value, std::nullptr_t>::type = nullptr> -std::string const& get_or(const toml::value& v, const T& opt) +template class M, template class V> +enable_if_t::type>::type, + std::string>::value, std::string> const& +get_or(const basic_value& v, T&& opt) { try { - return get(v); + return v.template cast().str; } catch(...) { return opt; } } -template::value, std::nullptr_t>::type = nullptr> -std::string& get_or(toml::value& v, T& opt) +template class M, template class V> +enable_if_t::type>::type, + std::string>::value, std::string>& +get_or(basic_value& v, T& opt) { try { - return get(v); + return v.template cast().str; } catch(...) { return opt; } } -template::value, std::nullptr_t>::type = nullptr> -std::string get_or(toml::value&& v, T&& opt) +template class M, template class V> +enable_if_t::type>::type, + std::string>::value, std::string> +get_or(basic_value&& v, T&& opt) { try { - return get(v); + return std::move(v.template cast().str); } catch(...) { return opt; } } -template::type>::value, - std::nullptr_t>::type = nullptr> -std::string get_or(const toml::value& v, T&& opt) + +// ---------------------------------------------------------------------------- +// specialization for string literal + +template class M, template class V> +enable_if_t::type>::value, std::string> +get_or(basic_value&& v, T&& opt) { try { - return get(v); + return std::move(v.template cast().str); } catch(...) { @@ -660,12 +675,14 @@ std::string get_or(const toml::value& v, T&& opt) // ---------------------------------------------------------------------------- // others (require type conversion and return type cannot be lvalue reference) -template>, +template class M, template class V> +enable_if_t>>, detail::negation>, detail::negation::type>> - >::value, std::nullptr_t>::type = nullptr> -T get_or(const toml::value& v, T&& opt) + >::value, T> +get_or(const basic_value& v, T&& opt) { try { @@ -678,6 +695,7 @@ T get_or(const toml::value& v, T&& opt) } } +/* // =========================================================================== // find_or(value, key, fallback)