diff --git a/toml/to_toml.hpp b/toml/to_toml.hpp index 9f373dd..9b8cde7 100644 --- a/toml/to_toml.hpp +++ b/toml/to_toml.hpp @@ -5,47 +5,76 @@ namespace toml { -template(), - typename std::enable_if<(vT != toml::value_t::Unknown && - vT != value_t::Empty), std::nullptr_t>::type = nullptr> -inline toml::value to_toml(T&& x) +template::value, std::nullptr_t>::type = nullptr> +inline value to_toml(const T& x) { - return toml::value(std::forward(x)); + return value(x); } -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> -toml::value to_toml(T&& x) +template>, std::is_integral + >::value, std::nullptr_t>::type = nullptr> +inline value to_toml(const T& x) { - toml::Array tmp; tmp.reserve(std::distance(std::begin(x), std::end(x))); + return value(::toml::Integer(x)); +} + +template>, std::is_floating_point + >::value, std::nullptr_t>::type = nullptr> +inline value to_toml(const T& x) +{ + return value(::toml::Float(x)); +} + +inline value to_toml(const char* str) +{ + return value(::toml::String(str)); +} + +template>, detail::is_container + >::value, std::nullptr_t>::type = nullptr> +value to_toml(const T& x) +{ + Array tmp; + tmp.reserve(std::distance(std::begin(x), std::end(x))); for(auto iter = std::begin(x); iter != std::end(x); ++iter) + { tmp.emplace_back(*iter); - return toml::value(std::move(tmp)); + } + return value(std::move(tmp)); } -template(), - typename std::enable_if<(vT == toml::value_t::Unknown) && - toml::detail::is_map::value, std::nullptr_t>::type = nullptr> -toml::value to_toml(T&& x) +template>, detail::is_map + >::value, std::nullptr_t>::type = nullptr> +value to_toml(const T& x) { - toml::Table tmp; + Table tmp; for(auto iter = std::begin(x); iter != std::end(x); ++iter) + { tmp.emplace(iter->first, to_toml(iter->second)); - return toml::value(std::move(tmp)); + } + return value(std::move(tmp)); } template -inline toml::value to_toml(std::initializer_list init) +inline value to_toml(std::initializer_list init) { - return toml::value(std::move(init)); + return value(std::move(init)); } -inline toml::value -to_toml(std::initializer_list> init) +inline value to_toml(std::initializer_list> init) { - return toml::value(std::move(init)); + return value(std::move(init)); +} + +template +inline value to_toml(const value& x) +{ + return x; } } // toml