From c15cb15c4c799e2c370978e479b9ec8f6df8af47 Mon Sep 17 00:00:00 2001 From: ToruNiina Date: Thu, 13 Dec 2018 00:38:04 +0900 Subject: [PATCH] simplify to_toml implementation --- toml/to_toml.hpp | 78 ++++++++++++------------------------------------ 1 file changed, 19 insertions(+), 59 deletions(-) diff --git a/toml/to_toml.hpp b/toml/to_toml.hpp index 9b8cde7..b8a5c29 100644 --- a/toml/to_toml.hpp +++ b/toml/to_toml.hpp @@ -5,76 +5,36 @@ namespace toml { -template::value, std::nullptr_t>::type = nullptr> -inline value to_toml(const T& x) +template +inline value to_toml(T&& x) { - return value(x); -} - -template>, std::is_integral - >::value, std::nullptr_t>::type = nullptr> -inline value to_toml(const T& 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 value(std::move(tmp)); -} - -template>, detail::is_map - >::value, std::nullptr_t>::type = nullptr> -value to_toml(const T& x) -{ - Table tmp; - for(auto iter = std::begin(x); iter != std::end(x); ++iter) - { - tmp.emplace(iter->first, to_toml(iter->second)); - } - return value(std::move(tmp)); + return value(std::forward(x)); } template -inline value to_toml(std::initializer_list init) +inline value to_toml(T&& x, string_t kind) { - return value(std::move(init)); + return value(std::forward(x), kind); } -inline value to_toml(std::initializer_list> init) +inline value to_toml(local_date d, local_time t) { - return value(std::move(init)); + return value(local_datetime(d, t)); +} +inline value to_toml(local_date d, local_time t, time_offset ofs) +{ + return value(offset_datetime(d, t, ofs)); } -template -inline value to_toml(const value& x) +template +inline value to_toml(Ts&& ... xs) { - return x; + return value(toml::array{toml::value(std::forward(xs)) ... }); +} + +inline value to_toml(std::initializer_list> xs) +{ + return value(toml::table(xs.begin(), xs.end())); } } // toml