#ifndef TOML11_UTILITY #define TOML11_UTILITY #include "traits.hpp" #include #include #include namespace toml { template inline std::unique_ptr make_unique(Ts&& ... args) { return std::unique_ptr(new T(std::forward(args)...)); } namespace detail { template inline void resize_impl(T& container, std::size_t N, std::true_type) { container.resize(N); return ; } template inline void resize_impl(T& container, std::size_t N, std::false_type) { if(container.size() >= N) return; else throw std::invalid_argument("not resizable type"); } } // detail template inline void resize(T& container, std::size_t N) { if(container.size() == N) return; 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) ...); } template T from_string(const std::string& str, U&& opt) { T v(std::forward(opt)); std::istringstream iss(str); iss >> v; return v; } }// toml #endif // TOML11_UTILITY