#ifndef TOML11_GET #define TOML11_GET #include "value.hpp" #include namespace toml { template::value, std::nullptr_t>::type = nullptr> inline T& get(value& v) { 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>, detail::is_container >::value, std::nullptr_t>::type = nullptr> T get(const value& v) { const auto& ar = v.cast(); T tmp; try { ::toml::resize(tmp, ar.size()); } catch(std::invalid_argument& iv) { throw type_error("toml::get: static array: size is not enough"); } std::transform(ar.cbegin(), ar.cend(), tmp.begin(), [](value const& elem){return get(elem);}); return tmp; } // table-like case template>, detail::is_map >::value, std::nullptr_t>::type = nullptr> T get(const toml::value& v) { const auto& tb = v.cast(); T tmp; for(const auto& kv : tb){tmp.insert(kv);} return tmp; } // get_or ----------------------------------------------------------------- template inline typename std::remove_cv::type>::type get_or(const toml::Table& tab, const toml::key& ky, T&& opt) { if(tab.count(ky) == 0) {return std::forward(opt);} return get::type>::type>(tab.find(ky)->second); } } // toml #endif// TOML11_GET