// Copyright Johannes Kapfhammer 2019. // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // pretty printing with c++ // #ifndef SOI_PRETTY #define SOI_PRETTY #include "prettyprint.hpp" namespace soi_h { template inline typename std::enable_if< ::pretty_print::is_container::value, std::basic_ostream &>::type pretty_print(std::basic_ostream & stream, const T & container) { return stream << ::pretty_print::print_container_helper(container); } template std::basic_ostream & pretty_print(std::basic_ostream & stream, const bool& x) { return stream << (x ? "true" : "false"); } namespace detail { template void escape_char(std::basic_ostream & stream, char c) { switch (c) { case '\a': stream << "\\a"; break; case '\b': stream << "\\b"; break; case '\t': stream << "\\t"; break; case '\n': stream << "\\n"; break; case '\v': stream << "\\v"; break; case '\f': stream << "\\f"; break; case '\r': stream << "\\r"; break; case '\e': stream << "\\e"; break; case '\"': stream << "\\\""; break; case '\'': stream << "\\'"; break; case '\?': stream << "\\?"; break; case '\\': stream << "\\\\"; break; default: stream << c; } } } template std::basic_ostream & pretty_print(std::basic_ostream & stream, const std::string& x) { stream << "\""; for (char c : x) detail::escape_char(stream, c); return stream << "\""; } template std::basic_ostream & pretty_print(std::basic_ostream & stream, char c) { stream << "'"; detail::escape_char(stream, c); return stream << "'"; } template inline typename std::enable_if< !::pretty_print::is_container::value, std::basic_ostream &>::type pretty_print(std::basic_ostream & stream, const T& x) { return stream << x; } } #endif // SOI_PRETTY