From e3f3f6470dd68484386a8ac34eb255ebc9b8c528 Mon Sep 17 00:00:00 2001 From: Johannes Kapfhammer Date: Thu, 10 Oct 2019 14:19:14 +0200 Subject: [PATCH] add missing file soi-io.hpp --- include/bits/soi-io.hpp | 82 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 include/bits/soi-io.hpp diff --git a/include/bits/soi-io.hpp b/include/bits/soi-io.hpp new file mode 100644 index 0000000..84a06a0 --- /dev/null +++ b/include/bits/soi-io.hpp @@ -0,0 +1,82 @@ +#include +#include +#include +#include + +template +T read() { + T x; + std::cin >> x; + return x; +} + +int read_int() { return read(); } +char read_char() { return read(); } +double read_double() { return read(); } +std::string read_string() { return read(); } +template +std::vector read_vector(int n) { + assert(n >= 0); + std::vector v; + v.reserve(n); + std::generate_n(std::back_inserter(v), n, read); + return v; +} + +namespace soi { + +namespace io { + +template +inline typename std::enable_if::value, + std::basic_ostream &>::type +print(std::basic_ostream &stream, const T &x) { + return stream << x; +} + +template +inline std::basic_ostream& +print(std::basic_ostream &stream, std::string const& x) { + return stream << x; +} + +template +std::basic_ostream & +print(std::basic_ostream &stream, const bool &x) { + return stream << (x ? "true" : "false"); +} + +struct space_separated_delims { + static const ::soi::prettyprint::delimiters_values values; +}; +const ::soi::prettyprint::delimiters_values space_separated_delims::values = { "", " ", "" }; + +template +inline typename std::enable_if<::soi::prettyprint::is_container::value, + std::basic_ostream &>::type +print(std::basic_ostream &stream, const T &x) { + return ::soi::prettyprint::pretty_print(stream, + soi::prettyprint::custom_delims(x)); +} + +template +void print_with_space(std::basic_ostream &stream, T&& x) { + stream << ' '; + ::soi::io::print(stream, std::forward(x)); +} + +} + +} + +template +void print(Arg&& arg, Args&&... args) { + soi::io::print(std::cout, arg); + using expander = bool[]; + (void)expander{0, (soi::io::print_with_space(std::cout, std::forward(args)), false)...}; + std::cout << '\n'; +} + +void print() { + std::cout << '\n'; +}