diff --git a/toml/serializer.hpp b/toml/serializer.hpp index 46a2b70..c733582 100644 --- a/toml/serializer.hpp +++ b/toml/serializer.hpp @@ -697,7 +697,8 @@ 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); + const auto serialized = visit(serializer(w, fprec, no_comment, false), v); + oss << serialized; return oss.str(); } return visit(serializer(w, fprec, force_inline), v); @@ -753,7 +754,8 @@ 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); + const auto serialized = visit(serializer(w, fprec, no_comment, false), v); + os << serialized; // if v is a non-table value, and has only one comment, then // put a comment just after a value. in the following way.