diff --git a/toml/get.hpp b/toml/get.hpp index c532fe5..147b0b7 100644 --- a/toml/get.hpp +++ b/toml/get.hpp @@ -6,51 +6,67 @@ namespace toml { -template(), - typename std::enable_if<(vT != toml::value_t::Unknown && - vT != value_t::Empty), std::nullptr_t>::type = nullptr> -inline T get(const toml::value& v) +template::value, std::nullptr_t>::type = nullptr> +inline T& get(value& v) { - return static_cast(v.cast()); + constexpr value_t kind = detail::check_type(); + return v.cast(); +} + +template::value, std::nullptr_t>::type = nullptr> +inline T const& get(const value& v) +{ + constexpr value_t kind = detail::check_type(); + return v.cast(); +} + +template>, + detail::negation>, std::is_integral + >::value, std::nullptr_t>::type = nullptr> +inline T get(const value& v) +{ + return static_cast(v.cast()); +} +template>, std::is_floating_point + >::value, std::nullptr_t>::type = nullptr> +inline T get(const value& v) +{ + return static_cast(v.cast()); } // array-like type -template(), - typename std::enable_if<(vT == toml::value_t::Unknown) && - (!toml::detail::is_map::value) && - toml::detail::is_container::value, std::nullptr_t>::type = nullptr> -T get(const toml::value& v) +template>, detail::is_container + >::value, std::nullptr_t>::type = nullptr> +T get(const value& v) { - if(v.type() != value_t::Array) - throw type_error("get: value type: " + stringize(v.type()) + - std::string(" is not argument type: Array")); - const auto& ar = v.cast(); T tmp; try { - toml::resize(tmp, ar.size()); + ::toml::resize(tmp, ar.size()); } catch(std::invalid_argument& iv) { - throw toml::type_error("toml::get: static array size is not enough"); + throw type_error("toml::get: static array: size is not enough"); } std::transform(ar.cbegin(), ar.cend(), tmp.begin(), - [](toml::value const& elem){return get(elem);}); + [](value const& elem){return get(elem);}); return tmp; } // table-like case -template(), - typename std::enable_if<(vT == toml::value_t::Unknown) && - toml::detail::is_map::value, std::nullptr_t>::type = nullptr> +template>, detail::is_map + >::value, std::nullptr_t>::type = nullptr> T get(const toml::value& v) { - if(v.type() != value_t::Table) - throw type_error("get: value type: " + stringize(v.type()) + - std::string(" is not argument type: Table")); - T tmp; const auto& tb = v.cast(); + T tmp; for(const auto& kv : tb){tmp.insert(kv);} return tmp; }