diff --git a/toml/serializer.hpp b/toml/serializer.hpp index 1a65d2b..5c4be90 100644 --- a/toml/serializer.hpp +++ b/toml/serializer.hpp @@ -49,12 +49,14 @@ inline std::string format_key(const toml::key& key) return token; } -template class Table, - template class Array> +template struct serializer { - using value_type = basic_value; + static_assert(detail::is_basic_value::value, + "toml::serializer is for toml::value and its variants, " + "toml::basic_value<...>."); + + using value_type = Value; using key_type = typename value_type::key_type ; using comment_type = typename value_type::comment_type ; using boolean_type = typename value_type::boolean_type ; @@ -717,6 +719,7 @@ format(const basic_value& v, std::size_t w = 80u, int fprec = std::numeric_limits::max_digits10, bool no_comment = false, bool force_inline = false) { + using value_type = basic_value; // if value is a table, it is considered to be a root object. // the root object can't be an inline table. if(v.is_table()) @@ -727,10 +730,10 @@ format(const basic_value& v, std::size_t w = 80u, oss << v.comments(); oss << '\n'; // to split the file comment from the first element } - oss << visit(serializer(w, fprec, no_comment, false), v); + oss << visit(serializer(w, fprec, no_comment, false), v); return oss.str(); } - return visit(serializer(w, fprec, force_inline), v); + return visit(serializer(w, fprec, force_inline), v); } namespace detail @@ -766,6 +769,8 @@ template& operator<<(std::basic_ostream& os, const basic_value& v) { + using value_type = basic_value; + // get status of std::setw(). const auto w = static_cast(os.width()); const int fprec = static_cast(os.precision()); @@ -781,7 +786,7 @@ operator<<(std::basic_ostream& os, const basic_value& v) os << '\n'; // to split the file comment from the first element } // the root object can't be an inline table. so pass `false`. - os << visit(serializer(w, fprec, false, no_comment), v); + os << visit(serializer(w, fprec, false, no_comment), v); // if v is a non-table value, and has only one comment, then // put a comment just after a value. in the following way.