#pragma GCC system_header #ifndef _LIBCXX_OSTREAM #define _LIBCXX_OSTREAM #include #include #include #include _LIBCXX_BEGIN_NAMESPACE_STD template > class basic_ostream : public basic_ios { public: using char_type = CharT; using traits_type = Traits; using int_type = typename traits_type::int_type; using pos_type = typename traits_type::pos_type; using off_type = typename traits_type::off_type; class sentry { public: explicit sentry(basic_ostream& os) : m_os(os) { } explicit operator bool() const { return true; } ~sentry() = default; private: basic_ostream& m_os; }; explicit basic_ostream(basic_streambuf* rdbuf) : basic_ios(rdbuf) { } virtual ~basic_ostream() = default; basic_ostream& put(char_type ch) { sentry sen(*this); if (sen) { if (this->rdbuf()->sputc(ch) == traits_type::eof()) { this->setstate(ios_base::badbit); } } return *this; } basic_ostream& write(const char_type* s, streamsize count) { sentry sen(*this); if (sen && count) { if (this->rdbuf()->sputn(s, count) != count) { this->setstate(ios_base::badbit); } } return *this; } basic_ostream& flush() { sentry sen(*this); if (sen) { if (this->rdbuf()->pubsync() == -1) { this->setstate(ios_base::badbit); } } return *this; } inline basic_ostream& operator<<(basic_ostream& (*callback)(basic_ostream&)) { return callback(*this); } private: }; template basic_ostream& operator<<(basic_ostream& os, int value) { char buf[16]; std::sprintf(buf, "%d", value); size_t len = std::strlen(buf); os.write(buf, len); return os; } template basic_ostream& operator<<(basic_ostream& os, long value) { char buf[16]; std::sprintf(buf, "%d", value); size_t len = std::strlen(buf); os.write(buf, len); return os; } template basic_ostream& operator<<(basic_ostream& os, unsigned int value) { char buf[16]; std::sprintf(buf, "%u", value); size_t len = std::strlen(buf); os.write(buf, len); return os; } template basic_ostream& operator<<(basic_ostream& os, unsigned long value) { char buf[16]; std::sprintf(buf, "%u", value); size_t len = std::strlen(buf); os.write(buf, len); return os; } template basic_ostream& operator<<(basic_ostream& os, const char* value) { size_t len = std::strlen(value); os.write(value, len); return os; } template basic_ostream& operator<<(basic_ostream& os, char value) { os.put(value); return os; } template basic_ostream& operator<<(basic_ostream& os, std::basic_string const& value) { os.write(value.data(), value.size()); return os; } template basic_ostream& operator<<(basic_ostream& os, std::basic_string_view const& value) { os.write(value.data(), value.size()); return os; } template basic_ostream& endl(basic_ostream& os) { os.put('\n'); os.flush(); return os; } typedef basic_ostream ostream; _LIBCXX_END_NAMESPACE_STD #endif // _LIBCXX_OSTREAM