From f83a8b450e68441a4f76ef3e71071a0bc80050b1 Mon Sep 17 00:00:00 2001 From: ToruNiina Date: Sun, 2 Dec 2018 23:05:15 +0900 Subject: [PATCH] add concat_to_string to utility for error messges --- toml/utility.hpp | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/toml/utility.hpp b/toml/utility.hpp index 0df0d07..2e7b0f0 100644 --- a/toml/utility.hpp +++ b/toml/utility.hpp @@ -3,6 +3,7 @@ #include "traits.hpp" #include #include +#include namespace toml { @@ -30,7 +31,7 @@ inline void resize_impl(T& container, std::size_t N, std::false_type) else throw std::invalid_argument("not resizable type"); } -} +} // detail template inline void resize(T& container, std::size_t N) @@ -39,5 +40,27 @@ inline void resize(T& container, std::size_t N) else return detail::resize_impl(container, N, detail::has_resize_method()); } +namespace detail +{ +inline std::string concat_to_string_impl(std::ostringstream& oss) +{ + return oss.str(); +} +template +std::string concat_to_string_impl(std::ostringstream& oss, T&& head, Ts&& ... tail) +{ + oss << std::forward(head); + return concat_to_string_impl(oss, std::forward(tail) ... ); +} +} // detail + +template +std::string concat_to_string(Ts&& ... args) +{ + std::ostringstream oss; + oss << std::boolalpha << std::fixed; + return detail::concat_to_string_impl(oss, std::forward(args) ...); +} + }// toml #endif // TOML11_UTILITY