Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | // -*- C++ -*- |
Louis Dionne | 9bd9388 | 2021-11-17 16:25:01 -0500 | [diff] [blame] | 2 | //===----------------------------------------------------------------------===// |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3 | // |
Chandler Carruth | d201210 | 2019-01-19 10:56:40 +0000 | [diff] [blame] | 4 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 5 | // See https://llvm.org/LICENSE.txt for license information. |
| 6 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #ifndef _LIBCPP_OSTREAM |
| 11 | #define _LIBCPP_OSTREAM |
| 12 | |
| 13 | /* |
| 14 | ostream synopsis |
| 15 | |
| 16 | template <class charT, class traits = char_traits<charT> > |
| 17 | class basic_ostream |
| 18 | : virtual public basic_ios<charT,traits> |
| 19 | { |
| 20 | public: |
| 21 | // types (inherited from basic_ios (27.5.4)): |
| 22 | typedef charT char_type; |
| 23 | typedef traits traits_type; |
| 24 | typedef typename traits_type::int_type int_type; |
| 25 | typedef typename traits_type::pos_type pos_type; |
| 26 | typedef typename traits_type::off_type off_type; |
| 27 | |
| 28 | // 27.7.2.2 Constructor/destructor: |
| 29 | explicit basic_ostream(basic_streambuf<char_type,traits>* sb); |
| 30 | basic_ostream(basic_ostream&& rhs); |
| 31 | virtual ~basic_ostream(); |
| 32 | |
| 33 | // 27.7.2.3 Assign/swap |
Marshall Clow | e9ca027 | 2013-08-14 15:15:28 +0000 | [diff] [blame] | 34 | basic_ostream& operator=(const basic_ostream& rhs) = delete; // C++14 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 35 | basic_ostream& operator=(basic_ostream&& rhs); |
| 36 | void swap(basic_ostream& rhs); |
| 37 | |
| 38 | // 27.7.2.4 Prefix/suffix: |
| 39 | class sentry; |
| 40 | |
| 41 | // 27.7.2.6 Formatted output: |
| 42 | basic_ostream& operator<<(basic_ostream& (*pf)(basic_ostream&)); |
| 43 | basic_ostream& operator<<(basic_ios<charT, traits>& (*pf)(basic_ios<charT,traits>&)); |
| 44 | basic_ostream& operator<<(ios_base& (*pf)(ios_base&)); |
| 45 | basic_ostream& operator<<(bool n); |
| 46 | basic_ostream& operator<<(short n); |
| 47 | basic_ostream& operator<<(unsigned short n); |
| 48 | basic_ostream& operator<<(int n); |
| 49 | basic_ostream& operator<<(unsigned int n); |
| 50 | basic_ostream& operator<<(long n); |
| 51 | basic_ostream& operator<<(unsigned long n); |
| 52 | basic_ostream& operator<<(long long n); |
| 53 | basic_ostream& operator<<(unsigned long long n); |
| 54 | basic_ostream& operator<<(float f); |
| 55 | basic_ostream& operator<<(double f); |
| 56 | basic_ostream& operator<<(long double f); |
| 57 | basic_ostream& operator<<(const void* p); |
Nikolas Klauser | d66919d | 2021-11-09 11:41:46 -0500 | [diff] [blame] | 58 | basic_ostream& operator<<(const volatile void* val); // C++23 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 59 | basic_ostream& operator<<(basic_streambuf<char_type,traits>* sb); |
Marshall Clow | 706862d | 2019-07-01 16:20:25 +0000 | [diff] [blame] | 60 | basic_ostream& operator<<(nullptr_t); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 61 | |
| 62 | // 27.7.2.7 Unformatted output: |
| 63 | basic_ostream& put(char_type c); |
| 64 | basic_ostream& write(const char_type* s, streamsize n); |
| 65 | basic_ostream& flush(); |
| 66 | |
| 67 | // 27.7.2.5 seeks: |
| 68 | pos_type tellp(); |
| 69 | basic_ostream& seekp(pos_type); |
| 70 | basic_ostream& seekp(off_type, ios_base::seekdir); |
Marshall Clow | 27d2987 | 2014-09-16 15:27:01 +0000 | [diff] [blame] | 71 | protected: |
| 72 | basic_ostream(const basic_ostream& rhs) = delete; |
| 73 | basic_ostream(basic_ostream&& rhs); |
| 74 | // 27.7.3.3 Assign/swap |
| 75 | basic_ostream& operator=(basic_ostream& rhs) = delete; |
| 76 | basic_ostream& operator=(const basic_ostream&& rhs); |
| 77 | void swap(basic_ostream& rhs); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 78 | }; |
| 79 | |
| 80 | // 27.7.2.6.4 character inserters |
| 81 | |
| 82 | template<class charT, class traits> |
| 83 | basic_ostream<charT,traits>& operator<<(basic_ostream<charT,traits>&, charT); |
| 84 | |
| 85 | template<class charT, class traits> |
| 86 | basic_ostream<charT,traits>& operator<<(basic_ostream<charT,traits>&, char); |
| 87 | |
| 88 | template<class traits> |
| 89 | basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&, char); |
| 90 | |
| 91 | // signed and unsigned |
| 92 | |
| 93 | template<class traits> |
| 94 | basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&, signed char); |
| 95 | |
| 96 | template<class traits> |
| 97 | basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&, unsigned char); |
| 98 | |
| 99 | // NTBS |
| 100 | template<class charT, class traits> |
| 101 | basic_ostream<charT,traits>& operator<<(basic_ostream<charT,traits>&, const charT*); |
| 102 | |
| 103 | template<class charT, class traits> |
| 104 | basic_ostream<charT,traits>& operator<<(basic_ostream<charT,traits>&, const char*); |
| 105 | |
| 106 | template<class traits> |
| 107 | basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&, const char*); |
| 108 | |
| 109 | // signed and unsigned |
| 110 | template<class traits> |
| 111 | basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&, const signed char*); |
| 112 | |
| 113 | template<class traits> |
| 114 | basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&, const unsigned char*); |
| 115 | |
| 116 | // swap: |
| 117 | template <class charT, class traits> |
| 118 | void swap(basic_ostream<charT, traits>& x, basic_ostream<charT, traits>& y); |
| 119 | |
| 120 | template <class charT, class traits> |
| 121 | basic_ostream<charT,traits>& endl(basic_ostream<charT,traits>& os); |
| 122 | |
| 123 | template <class charT, class traits> |
| 124 | basic_ostream<charT,traits>& ends(basic_ostream<charT,traits>& os); |
| 125 | |
| 126 | template <class charT, class traits> |
| 127 | basic_ostream<charT,traits>& flush(basic_ostream<charT,traits>& os); |
| 128 | |
| 129 | // rvalue stream insertion |
Louis Dionne | d9f73b1 | 2020-09-23 08:49:00 -0400 | [diff] [blame] | 130 | template <class Stream, class T> |
| 131 | Stream&& operator<<(Stream&& os, const T& x); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 132 | |
| 133 | } // std |
| 134 | |
| 135 | */ |
| 136 | |
| 137 | #include <__config> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 138 | #include <bitset> |
Arthur O'Dwyer | ef18160 | 2021-05-19 11:57:04 -0400 | [diff] [blame] | 139 | #include <ios> |
| 140 | #include <iterator> |
| 141 | #include <locale> |
| 142 | #include <streambuf> |
Marshall Clow | 8732fed | 2018-12-11 04:35:44 +0000 | [diff] [blame] | 143 | #include <version> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 144 | |
Howard Hinnant | aaaa52b | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 145 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 146 | #pragma GCC system_header |
Howard Hinnant | aaaa52b | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 147 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 148 | |
| 149 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 150 | |
| 151 | template <class _CharT, class _Traits> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 152 | class _LIBCPP_TEMPLATE_VIS basic_ostream |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 153 | : virtual public basic_ios<_CharT, _Traits> |
| 154 | { |
| 155 | public: |
| 156 | // types (inherited from basic_ios (27.5.4)): |
| 157 | typedef _CharT char_type; |
| 158 | typedef _Traits traits_type; |
| 159 | typedef typename traits_type::int_type int_type; |
| 160 | typedef typename traits_type::pos_type pos_type; |
| 161 | typedef typename traits_type::off_type off_type; |
| 162 | |
| 163 | // 27.7.2.2 Constructor/destructor: |
Louis Dionne | b4d05d7 | 2018-10-16 19:26:23 +0000 | [diff] [blame] | 164 | inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 |
Eric Fiselier | 815ed73 | 2016-09-16 00:00:48 +0000 | [diff] [blame] | 165 | explicit basic_ostream(basic_streambuf<char_type, traits_type>* __sb) |
| 166 | { this->init(__sb); } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 167 | virtual ~basic_ostream(); |
| 168 | protected: |
Eric Fiselier | 815ed73 | 2016-09-16 00:00:48 +0000 | [diff] [blame] | 169 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 170 | basic_ostream(basic_ostream&& __rhs); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 171 | |
| 172 | // 27.7.2.3 Assign/swap |
Eric Fiselier | 815ed73 | 2016-09-16 00:00:48 +0000 | [diff] [blame] | 173 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 174 | basic_ostream& operator=(basic_ostream&& __rhs); |
Arthur O'Dwyer | 8dcd298 | 2021-06-15 12:47:05 -0400 | [diff] [blame] | 175 | |
Louis Dionne | b4d05d7 | 2018-10-16 19:26:23 +0000 | [diff] [blame] | 176 | inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 |
Eric Fiselier | 815ed73 | 2016-09-16 00:00:48 +0000 | [diff] [blame] | 177 | void swap(basic_ostream& __rhs) |
| 178 | { basic_ios<char_type, traits_type>::swap(__rhs); } |
Marshall Clow | 27d2987 | 2014-09-16 15:27:01 +0000 | [diff] [blame] | 179 | |
Marshall Clow | 242d9c1 | 2014-09-16 15:33:53 +0000 | [diff] [blame] | 180 | basic_ostream (const basic_ostream& __rhs) = delete; |
| 181 | basic_ostream& operator=(const basic_ostream& __rhs) = delete; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 182 | |
Arthur O'Dwyer | 8dcd298 | 2021-06-15 12:47:05 -0400 | [diff] [blame] | 183 | public: |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 184 | // 27.7.2.4 Prefix/suffix: |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 185 | class _LIBCPP_TEMPLATE_VIS sentry; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 186 | |
| 187 | // 27.7.2.6 Formatted output: |
Louis Dionne | b4d05d7 | 2018-10-16 19:26:23 +0000 | [diff] [blame] | 188 | inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 |
Eric Fiselier | 815ed73 | 2016-09-16 00:00:48 +0000 | [diff] [blame] | 189 | basic_ostream& operator<<(basic_ostream& (*__pf)(basic_ostream&)) |
| 190 | { return __pf(*this); } |
| 191 | |
Louis Dionne | b4d05d7 | 2018-10-16 19:26:23 +0000 | [diff] [blame] | 192 | inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 193 | basic_ostream& operator<<(basic_ios<char_type, traits_type>& |
Eric Fiselier | 815ed73 | 2016-09-16 00:00:48 +0000 | [diff] [blame] | 194 | (*__pf)(basic_ios<char_type,traits_type>&)) |
| 195 | { __pf(*this); return *this; } |
| 196 | |
Louis Dionne | b4d05d7 | 2018-10-16 19:26:23 +0000 | [diff] [blame] | 197 | inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 |
Eric Fiselier | 815ed73 | 2016-09-16 00:00:48 +0000 | [diff] [blame] | 198 | basic_ostream& operator<<(ios_base& (*__pf)(ios_base&)) |
| 199 | { __pf(*this); return *this; } |
| 200 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 201 | basic_ostream& operator<<(bool __n); |
| 202 | basic_ostream& operator<<(short __n); |
| 203 | basic_ostream& operator<<(unsigned short __n); |
| 204 | basic_ostream& operator<<(int __n); |
| 205 | basic_ostream& operator<<(unsigned int __n); |
| 206 | basic_ostream& operator<<(long __n); |
| 207 | basic_ostream& operator<<(unsigned long __n); |
| 208 | basic_ostream& operator<<(long long __n); |
| 209 | basic_ostream& operator<<(unsigned long long __n); |
| 210 | basic_ostream& operator<<(float __f); |
| 211 | basic_ostream& operator<<(double __f); |
| 212 | basic_ostream& operator<<(long double __f); |
| 213 | basic_ostream& operator<<(const void* __p); |
Nikolas Klauser | d66919d | 2021-11-09 11:41:46 -0500 | [diff] [blame] | 214 | |
| 215 | #if _LIBCPP_STD_VER > 20 |
| 216 | _LIBCPP_HIDE_FROM_ABI |
| 217 | basic_ostream& operator<<(const volatile void* __p) { |
| 218 | return operator<<(const_cast<const void*>(__p)); |
| 219 | } |
| 220 | #endif |
| 221 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 222 | basic_ostream& operator<<(basic_streambuf<char_type, traits_type>* __sb); |
| 223 | |
Marshall Clow | 706862d | 2019-07-01 16:20:25 +0000 | [diff] [blame] | 224 | _LIBCPP_INLINE_VISIBILITY |
| 225 | basic_ostream& operator<<(nullptr_t) |
| 226 | { return *this << "nullptr"; } |
| 227 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 228 | // 27.7.2.7 Unformatted output: |
| 229 | basic_ostream& put(char_type __c); |
| 230 | basic_ostream& write(const char_type* __s, streamsize __n); |
| 231 | basic_ostream& flush(); |
| 232 | |
| 233 | // 27.7.2.5 seeks: |
Louis Dionne | b4d05d7 | 2018-10-16 19:26:23 +0000 | [diff] [blame] | 234 | inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 235 | pos_type tellp(); |
Louis Dionne | b4d05d7 | 2018-10-16 19:26:23 +0000 | [diff] [blame] | 236 | inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 237 | basic_ostream& seekp(pos_type __pos); |
Louis Dionne | b4d05d7 | 2018-10-16 19:26:23 +0000 | [diff] [blame] | 238 | inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 239 | basic_ostream& seekp(off_type __off, ios_base::seekdir __dir); |
| 240 | |
| 241 | protected: |
Louis Dionne | 16fe295 | 2018-07-11 23:14:33 +0000 | [diff] [blame] | 242 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 243 | basic_ostream() {} // extension, intentially does not initialize |
| 244 | }; |
| 245 | |
| 246 | template <class _CharT, class _Traits> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 247 | class _LIBCPP_TEMPLATE_VIS basic_ostream<_CharT, _Traits>::sentry |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 248 | { |
| 249 | bool __ok_; |
| 250 | basic_ostream<_CharT, _Traits>& __os_; |
| 251 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 252 | public: |
| 253 | explicit sentry(basic_ostream<_CharT, _Traits>& __os); |
| 254 | ~sentry(); |
Nikolas Klauser | 0708864 | 2021-12-08 10:57:12 +0100 | [diff] [blame] | 255 | sentry(const sentry&) = delete; |
| 256 | sentry& operator=(const sentry&) = delete; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 257 | |
Louis Dionne | 16fe295 | 2018-07-11 23:14:33 +0000 | [diff] [blame] | 258 | _LIBCPP_INLINE_VISIBILITY |
Arthur O'Dwyer | 6c9c9a7 | 2021-06-15 12:57:54 -0400 | [diff] [blame] | 259 | explicit operator bool() const {return __ok_;} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 260 | }; |
| 261 | |
| 262 | template <class _CharT, class _Traits> |
| 263 | basic_ostream<_CharT, _Traits>::sentry::sentry(basic_ostream<_CharT, _Traits>& __os) |
| 264 | : __ok_(false), |
| 265 | __os_(__os) |
| 266 | { |
| 267 | if (__os.good()) |
| 268 | { |
| 269 | if (__os.tie()) |
| 270 | __os.tie()->flush(); |
| 271 | __ok_ = true; |
| 272 | } |
| 273 | } |
| 274 | |
| 275 | template <class _CharT, class _Traits> |
| 276 | basic_ostream<_CharT, _Traits>::sentry::~sentry() |
| 277 | { |
| 278 | if (__os_.rdbuf() && __os_.good() && (__os_.flags() & ios_base::unitbuf) |
| 279 | && !uncaught_exception()) |
| 280 | { |
| 281 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 282 | try |
| 283 | { |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 284 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 285 | if (__os_.rdbuf()->pubsync() == -1) |
| 286 | __os_.setstate(ios_base::badbit); |
| 287 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 288 | } |
| 289 | catch (...) |
| 290 | { |
| 291 | } |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 292 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 293 | } |
| 294 | } |
| 295 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 296 | template <class _CharT, class _Traits> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 297 | basic_ostream<_CharT, _Traits>::basic_ostream(basic_ostream&& __rhs) |
| 298 | { |
| 299 | this->move(__rhs); |
| 300 | } |
| 301 | |
| 302 | template <class _CharT, class _Traits> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 303 | basic_ostream<_CharT, _Traits>& |
| 304 | basic_ostream<_CharT, _Traits>::operator=(basic_ostream&& __rhs) |
| 305 | { |
| 306 | swap(__rhs); |
| 307 | return *this; |
| 308 | } |
| 309 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 310 | template <class _CharT, class _Traits> |
| 311 | basic_ostream<_CharT, _Traits>::~basic_ostream() |
| 312 | { |
| 313 | } |
| 314 | |
| 315 | template <class _CharT, class _Traits> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 316 | basic_ostream<_CharT, _Traits>& |
| 317 | basic_ostream<_CharT, _Traits>::operator<<(basic_streambuf<char_type, traits_type>* __sb) |
| 318 | { |
| 319 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 320 | try |
| 321 | { |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 322 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 323 | sentry __s(*this); |
| 324 | if (__s) |
| 325 | { |
| 326 | if (__sb) |
| 327 | { |
| 328 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 329 | try |
| 330 | { |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 331 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 332 | typedef istreambuf_iterator<_CharT, _Traits> _Ip; |
| 333 | typedef ostreambuf_iterator<_CharT, _Traits> _Op; |
| 334 | _Ip __i(__sb); |
| 335 | _Ip __eof; |
| 336 | _Op __o(*this); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 337 | size_t __c = 0; |
| 338 | for (; __i != __eof; ++__i, ++__o, ++__c) |
| 339 | { |
| 340 | *__o = *__i; |
| 341 | if (__o.failed()) |
| 342 | break; |
| 343 | } |
| 344 | if (__c == 0) |
| 345 | this->setstate(ios_base::failbit); |
| 346 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 347 | } |
| 348 | catch (...) |
| 349 | { |
| 350 | this->__set_failbit_and_consider_rethrow(); |
| 351 | } |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 352 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 353 | } |
| 354 | else |
| 355 | this->setstate(ios_base::badbit); |
| 356 | } |
| 357 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 358 | } |
| 359 | catch (...) |
| 360 | { |
| 361 | this->__set_badbit_and_consider_rethrow(); |
| 362 | } |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 363 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 364 | return *this; |
| 365 | } |
| 366 | |
| 367 | template <class _CharT, class _Traits> |
| 368 | basic_ostream<_CharT, _Traits>& |
| 369 | basic_ostream<_CharT, _Traits>::operator<<(bool __n) |
| 370 | { |
| 371 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 372 | try |
| 373 | { |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 374 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 375 | sentry __s(*this); |
| 376 | if (__s) |
| 377 | { |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 378 | typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp; |
| 379 | const _Fp& __f = use_facet<_Fp>(this->getloc()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 380 | if (__f.put(*this, *this, this->fill(), __n).failed()) |
| 381 | this->setstate(ios_base::badbit | ios_base::failbit); |
| 382 | } |
| 383 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 384 | } |
| 385 | catch (...) |
| 386 | { |
| 387 | this->__set_badbit_and_consider_rethrow(); |
| 388 | } |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 389 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 390 | return *this; |
| 391 | } |
| 392 | |
| 393 | template <class _CharT, class _Traits> |
| 394 | basic_ostream<_CharT, _Traits>& |
| 395 | basic_ostream<_CharT, _Traits>::operator<<(short __n) |
| 396 | { |
| 397 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 398 | try |
| 399 | { |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 400 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 401 | sentry __s(*this); |
| 402 | if (__s) |
| 403 | { |
| 404 | ios_base::fmtflags __flags = ios_base::flags() & ios_base::basefield; |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 405 | typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp; |
| 406 | const _Fp& __f = use_facet<_Fp>(this->getloc()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 407 | if (__f.put(*this, *this, this->fill(), |
| 408 | __flags == ios_base::oct || __flags == ios_base::hex ? |
| 409 | static_cast<long>(static_cast<unsigned short>(__n)) : |
| 410 | static_cast<long>(__n)).failed()) |
| 411 | this->setstate(ios_base::badbit | ios_base::failbit); |
| 412 | } |
| 413 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 414 | } |
| 415 | catch (...) |
| 416 | { |
| 417 | this->__set_badbit_and_consider_rethrow(); |
| 418 | } |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 419 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 420 | return *this; |
| 421 | } |
| 422 | |
| 423 | template <class _CharT, class _Traits> |
| 424 | basic_ostream<_CharT, _Traits>& |
| 425 | basic_ostream<_CharT, _Traits>::operator<<(unsigned short __n) |
| 426 | { |
| 427 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 428 | try |
| 429 | { |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 430 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 431 | sentry __s(*this); |
| 432 | if (__s) |
| 433 | { |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 434 | typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp; |
| 435 | const _Fp& __f = use_facet<_Fp>(this->getloc()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 436 | if (__f.put(*this, *this, this->fill(), static_cast<unsigned long>(__n)).failed()) |
| 437 | this->setstate(ios_base::badbit | ios_base::failbit); |
| 438 | } |
| 439 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 440 | } |
| 441 | catch (...) |
| 442 | { |
| 443 | this->__set_badbit_and_consider_rethrow(); |
| 444 | } |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 445 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 446 | return *this; |
| 447 | } |
| 448 | |
| 449 | template <class _CharT, class _Traits> |
| 450 | basic_ostream<_CharT, _Traits>& |
| 451 | basic_ostream<_CharT, _Traits>::operator<<(int __n) |
| 452 | { |
| 453 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 454 | try |
| 455 | { |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 456 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 457 | sentry __s(*this); |
| 458 | if (__s) |
| 459 | { |
| 460 | ios_base::fmtflags __flags = ios_base::flags() & ios_base::basefield; |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 461 | typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp; |
| 462 | const _Fp& __f = use_facet<_Fp>(this->getloc()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 463 | if (__f.put(*this, *this, this->fill(), |
| 464 | __flags == ios_base::oct || __flags == ios_base::hex ? |
| 465 | static_cast<long>(static_cast<unsigned int>(__n)) : |
| 466 | static_cast<long>(__n)).failed()) |
| 467 | this->setstate(ios_base::badbit | ios_base::failbit); |
| 468 | } |
| 469 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 470 | } |
| 471 | catch (...) |
| 472 | { |
| 473 | this->__set_badbit_and_consider_rethrow(); |
| 474 | } |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 475 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 476 | return *this; |
| 477 | } |
| 478 | |
| 479 | template <class _CharT, class _Traits> |
| 480 | basic_ostream<_CharT, _Traits>& |
| 481 | basic_ostream<_CharT, _Traits>::operator<<(unsigned int __n) |
| 482 | { |
| 483 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 484 | try |
| 485 | { |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 486 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 487 | sentry __s(*this); |
| 488 | if (__s) |
| 489 | { |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 490 | typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp; |
| 491 | const _Fp& __f = use_facet<_Fp>(this->getloc()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 492 | if (__f.put(*this, *this, this->fill(), static_cast<unsigned long>(__n)).failed()) |
| 493 | this->setstate(ios_base::badbit | ios_base::failbit); |
| 494 | } |
| 495 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 496 | } |
| 497 | catch (...) |
| 498 | { |
| 499 | this->__set_badbit_and_consider_rethrow(); |
| 500 | } |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 501 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 502 | return *this; |
| 503 | } |
| 504 | |
| 505 | template <class _CharT, class _Traits> |
| 506 | basic_ostream<_CharT, _Traits>& |
| 507 | basic_ostream<_CharT, _Traits>::operator<<(long __n) |
| 508 | { |
| 509 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 510 | try |
| 511 | { |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 512 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 513 | sentry __s(*this); |
| 514 | if (__s) |
| 515 | { |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 516 | typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp; |
| 517 | const _Fp& __f = use_facet<_Fp>(this->getloc()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 518 | if (__f.put(*this, *this, this->fill(), __n).failed()) |
| 519 | this->setstate(ios_base::badbit | ios_base::failbit); |
| 520 | } |
| 521 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 522 | } |
| 523 | catch (...) |
| 524 | { |
| 525 | this->__set_badbit_and_consider_rethrow(); |
| 526 | } |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 527 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 528 | return *this; |
| 529 | } |
| 530 | |
| 531 | template <class _CharT, class _Traits> |
| 532 | basic_ostream<_CharT, _Traits>& |
| 533 | basic_ostream<_CharT, _Traits>::operator<<(unsigned long __n) |
| 534 | { |
| 535 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 536 | try |
| 537 | { |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 538 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 539 | sentry __s(*this); |
| 540 | if (__s) |
| 541 | { |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 542 | typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp; |
| 543 | const _Fp& __f = use_facet<_Fp>(this->getloc()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 544 | if (__f.put(*this, *this, this->fill(), __n).failed()) |
| 545 | this->setstate(ios_base::badbit | ios_base::failbit); |
| 546 | } |
| 547 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 548 | } |
| 549 | catch (...) |
| 550 | { |
| 551 | this->__set_badbit_and_consider_rethrow(); |
| 552 | } |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 553 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 554 | return *this; |
| 555 | } |
| 556 | |
| 557 | template <class _CharT, class _Traits> |
| 558 | basic_ostream<_CharT, _Traits>& |
| 559 | basic_ostream<_CharT, _Traits>::operator<<(long long __n) |
| 560 | { |
| 561 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 562 | try |
| 563 | { |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 564 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 565 | sentry __s(*this); |
| 566 | if (__s) |
| 567 | { |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 568 | typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp; |
| 569 | const _Fp& __f = use_facet<_Fp>(this->getloc()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 570 | if (__f.put(*this, *this, this->fill(), __n).failed()) |
| 571 | this->setstate(ios_base::badbit | ios_base::failbit); |
| 572 | } |
| 573 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 574 | } |
| 575 | catch (...) |
| 576 | { |
| 577 | this->__set_badbit_and_consider_rethrow(); |
| 578 | } |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 579 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 580 | return *this; |
| 581 | } |
| 582 | |
| 583 | template <class _CharT, class _Traits> |
| 584 | basic_ostream<_CharT, _Traits>& |
| 585 | basic_ostream<_CharT, _Traits>::operator<<(unsigned long long __n) |
| 586 | { |
| 587 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 588 | try |
| 589 | { |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 590 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 591 | sentry __s(*this); |
| 592 | if (__s) |
| 593 | { |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 594 | typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp; |
| 595 | const _Fp& __f = use_facet<_Fp>(this->getloc()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 596 | if (__f.put(*this, *this, this->fill(), __n).failed()) |
| 597 | this->setstate(ios_base::badbit | ios_base::failbit); |
| 598 | } |
| 599 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 600 | } |
| 601 | catch (...) |
| 602 | { |
| 603 | this->__set_badbit_and_consider_rethrow(); |
| 604 | } |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 605 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 606 | return *this; |
| 607 | } |
| 608 | |
| 609 | template <class _CharT, class _Traits> |
| 610 | basic_ostream<_CharT, _Traits>& |
| 611 | basic_ostream<_CharT, _Traits>::operator<<(float __n) |
| 612 | { |
| 613 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 614 | try |
| 615 | { |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 616 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 617 | sentry __s(*this); |
| 618 | if (__s) |
| 619 | { |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 620 | typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp; |
| 621 | const _Fp& __f = use_facet<_Fp>(this->getloc()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 622 | if (__f.put(*this, *this, this->fill(), static_cast<double>(__n)).failed()) |
| 623 | this->setstate(ios_base::badbit | ios_base::failbit); |
| 624 | } |
| 625 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 626 | } |
| 627 | catch (...) |
| 628 | { |
| 629 | this->__set_badbit_and_consider_rethrow(); |
| 630 | } |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 631 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 632 | return *this; |
| 633 | } |
| 634 | |
| 635 | template <class _CharT, class _Traits> |
| 636 | basic_ostream<_CharT, _Traits>& |
| 637 | basic_ostream<_CharT, _Traits>::operator<<(double __n) |
| 638 | { |
| 639 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 640 | try |
| 641 | { |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 642 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 643 | sentry __s(*this); |
| 644 | if (__s) |
| 645 | { |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 646 | typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp; |
| 647 | const _Fp& __f = use_facet<_Fp>(this->getloc()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 648 | if (__f.put(*this, *this, this->fill(), __n).failed()) |
| 649 | this->setstate(ios_base::badbit | ios_base::failbit); |
| 650 | } |
| 651 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 652 | } |
| 653 | catch (...) |
| 654 | { |
| 655 | this->__set_badbit_and_consider_rethrow(); |
| 656 | } |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 657 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 658 | return *this; |
| 659 | } |
| 660 | |
| 661 | template <class _CharT, class _Traits> |
| 662 | basic_ostream<_CharT, _Traits>& |
| 663 | basic_ostream<_CharT, _Traits>::operator<<(long double __n) |
| 664 | { |
| 665 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 666 | try |
| 667 | { |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 668 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 669 | sentry __s(*this); |
| 670 | if (__s) |
| 671 | { |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 672 | typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp; |
| 673 | const _Fp& __f = use_facet<_Fp>(this->getloc()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 674 | if (__f.put(*this, *this, this->fill(), __n).failed()) |
| 675 | this->setstate(ios_base::badbit | ios_base::failbit); |
| 676 | } |
| 677 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 678 | } |
| 679 | catch (...) |
| 680 | { |
| 681 | this->__set_badbit_and_consider_rethrow(); |
| 682 | } |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 683 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 684 | return *this; |
| 685 | } |
| 686 | |
| 687 | template <class _CharT, class _Traits> |
| 688 | basic_ostream<_CharT, _Traits>& |
| 689 | basic_ostream<_CharT, _Traits>::operator<<(const void* __n) |
| 690 | { |
| 691 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 692 | try |
| 693 | { |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 694 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 695 | sentry __s(*this); |
| 696 | if (__s) |
| 697 | { |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 698 | typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp; |
| 699 | const _Fp& __f = use_facet<_Fp>(this->getloc()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 700 | if (__f.put(*this, *this, this->fill(), __n).failed()) |
| 701 | this->setstate(ios_base::badbit | ios_base::failbit); |
| 702 | } |
| 703 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 704 | } |
| 705 | catch (...) |
| 706 | { |
| 707 | this->__set_badbit_and_consider_rethrow(); |
| 708 | } |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 709 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 710 | return *this; |
| 711 | } |
| 712 | |
| 713 | template<class _CharT, class _Traits> |
| 714 | basic_ostream<_CharT, _Traits>& |
Marshall Clow | 0099564 | 2013-12-10 19:25:49 +0000 | [diff] [blame] | 715 | __put_character_sequence(basic_ostream<_CharT, _Traits>& __os, |
| 716 | const _CharT* __str, size_t __len) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 717 | { |
| 718 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 719 | try |
| 720 | { |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 721 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 722 | typename basic_ostream<_CharT, _Traits>::sentry __s(__os); |
| 723 | if (__s) |
| 724 | { |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 725 | typedef ostreambuf_iterator<_CharT, _Traits> _Ip; |
| 726 | if (__pad_and_output(_Ip(__os), |
Marshall Clow | 0099564 | 2013-12-10 19:25:49 +0000 | [diff] [blame] | 727 | __str, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 728 | (__os.flags() & ios_base::adjustfield) == ios_base::left ? |
Marshall Clow | 0099564 | 2013-12-10 19:25:49 +0000 | [diff] [blame] | 729 | __str + __len : |
| 730 | __str, |
| 731 | __str + __len, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 732 | __os, |
| 733 | __os.fill()).failed()) |
| 734 | __os.setstate(ios_base::badbit | ios_base::failbit); |
| 735 | } |
| 736 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 737 | } |
| 738 | catch (...) |
| 739 | { |
| 740 | __os.__set_badbit_and_consider_rethrow(); |
| 741 | } |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 742 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 743 | return __os; |
| 744 | } |
| 745 | |
Volodymyr Sapsai | 4c14a92 | 2018-09-19 23:31:34 +0000 | [diff] [blame] | 746 | |
Marshall Clow | 0099564 | 2013-12-10 19:25:49 +0000 | [diff] [blame] | 747 | template<class _CharT, class _Traits> |
| 748 | basic_ostream<_CharT, _Traits>& |
| 749 | operator<<(basic_ostream<_CharT, _Traits>& __os, _CharT __c) |
| 750 | { |
Marshall Clow | 4bc2be2 | 2014-02-16 01:57:26 +0000 | [diff] [blame] | 751 | return _VSTD::__put_character_sequence(__os, &__c, 1); |
Marshall Clow | 0099564 | 2013-12-10 19:25:49 +0000 | [diff] [blame] | 752 | } |
| 753 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 754 | template<class _CharT, class _Traits> |
| 755 | basic_ostream<_CharT, _Traits>& |
| 756 | operator<<(basic_ostream<_CharT, _Traits>& __os, char __cn) |
| 757 | { |
| 758 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 759 | try |
| 760 | { |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 761 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 762 | typename basic_ostream<_CharT, _Traits>::sentry __s(__os); |
| 763 | if (__s) |
| 764 | { |
| 765 | _CharT __c = __os.widen(__cn); |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 766 | typedef ostreambuf_iterator<_CharT, _Traits> _Ip; |
| 767 | if (__pad_and_output(_Ip(__os), |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 768 | &__c, |
| 769 | (__os.flags() & ios_base::adjustfield) == ios_base::left ? |
| 770 | &__c + 1 : |
| 771 | &__c, |
| 772 | &__c + 1, |
| 773 | __os, |
| 774 | __os.fill()).failed()) |
| 775 | __os.setstate(ios_base::badbit | ios_base::failbit); |
| 776 | } |
| 777 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 778 | } |
| 779 | catch (...) |
| 780 | { |
| 781 | __os.__set_badbit_and_consider_rethrow(); |
| 782 | } |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 783 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 784 | return __os; |
| 785 | } |
| 786 | |
| 787 | template<class _Traits> |
| 788 | basic_ostream<char, _Traits>& |
| 789 | operator<<(basic_ostream<char, _Traits>& __os, char __c) |
| 790 | { |
Marshall Clow | 4bc2be2 | 2014-02-16 01:57:26 +0000 | [diff] [blame] | 791 | return _VSTD::__put_character_sequence(__os, &__c, 1); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 792 | } |
| 793 | |
| 794 | template<class _Traits> |
| 795 | basic_ostream<char, _Traits>& |
| 796 | operator<<(basic_ostream<char, _Traits>& __os, signed char __c) |
| 797 | { |
Marshall Clow | 4bc2be2 | 2014-02-16 01:57:26 +0000 | [diff] [blame] | 798 | return _VSTD::__put_character_sequence(__os, (char *) &__c, 1); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 799 | } |
| 800 | |
| 801 | template<class _Traits> |
| 802 | basic_ostream<char, _Traits>& |
| 803 | operator<<(basic_ostream<char, _Traits>& __os, unsigned char __c) |
| 804 | { |
Marshall Clow | 4bc2be2 | 2014-02-16 01:57:26 +0000 | [diff] [blame] | 805 | return _VSTD::__put_character_sequence(__os, (char *) &__c, 1); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 806 | } |
| 807 | |
| 808 | template<class _CharT, class _Traits> |
| 809 | basic_ostream<_CharT, _Traits>& |
| 810 | operator<<(basic_ostream<_CharT, _Traits>& __os, const _CharT* __str) |
| 811 | { |
Marshall Clow | 4bc2be2 | 2014-02-16 01:57:26 +0000 | [diff] [blame] | 812 | return _VSTD::__put_character_sequence(__os, __str, _Traits::length(__str)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 813 | } |
| 814 | |
| 815 | template<class _CharT, class _Traits> |
| 816 | basic_ostream<_CharT, _Traits>& |
| 817 | operator<<(basic_ostream<_CharT, _Traits>& __os, const char* __strn) |
| 818 | { |
| 819 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 820 | try |
| 821 | { |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 822 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 823 | typename basic_ostream<_CharT, _Traits>::sentry __s(__os); |
| 824 | if (__s) |
| 825 | { |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 826 | typedef ostreambuf_iterator<_CharT, _Traits> _Ip; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 827 | size_t __len = char_traits<char>::length(__strn); |
| 828 | const int __bs = 100; |
| 829 | _CharT __wbb[__bs]; |
| 830 | _CharT* __wb = __wbb; |
| 831 | unique_ptr<_CharT, void(*)(void*)> __h(0, free); |
| 832 | if (__len > __bs) |
| 833 | { |
| 834 | __wb = (_CharT*)malloc(__len*sizeof(_CharT)); |
| 835 | if (__wb == 0) |
| 836 | __throw_bad_alloc(); |
| 837 | __h.reset(__wb); |
| 838 | } |
| 839 | for (_CharT* __p = __wb; *__strn != '\0'; ++__strn, ++__p) |
| 840 | *__p = __os.widen(*__strn); |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 841 | if (__pad_and_output(_Ip(__os), |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 842 | __wb, |
| 843 | (__os.flags() & ios_base::adjustfield) == ios_base::left ? |
| 844 | __wb + __len : |
| 845 | __wb, |
| 846 | __wb + __len, |
| 847 | __os, |
| 848 | __os.fill()).failed()) |
| 849 | __os.setstate(ios_base::badbit | ios_base::failbit); |
| 850 | } |
| 851 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 852 | } |
| 853 | catch (...) |
| 854 | { |
| 855 | __os.__set_badbit_and_consider_rethrow(); |
| 856 | } |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 857 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 858 | return __os; |
| 859 | } |
| 860 | |
| 861 | template<class _Traits> |
| 862 | basic_ostream<char, _Traits>& |
| 863 | operator<<(basic_ostream<char, _Traits>& __os, const char* __str) |
| 864 | { |
Marshall Clow | 4bc2be2 | 2014-02-16 01:57:26 +0000 | [diff] [blame] | 865 | return _VSTD::__put_character_sequence(__os, __str, _Traits::length(__str)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 866 | } |
| 867 | |
| 868 | template<class _Traits> |
| 869 | basic_ostream<char, _Traits>& |
| 870 | operator<<(basic_ostream<char, _Traits>& __os, const signed char* __str) |
| 871 | { |
Marshall Clow | 4bc2be2 | 2014-02-16 01:57:26 +0000 | [diff] [blame] | 872 | const char *__s = (const char *) __str; |
| 873 | return _VSTD::__put_character_sequence(__os, __s, _Traits::length(__s)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 874 | } |
| 875 | |
| 876 | template<class _Traits> |
| 877 | basic_ostream<char, _Traits>& |
| 878 | operator<<(basic_ostream<char, _Traits>& __os, const unsigned char* __str) |
| 879 | { |
Marshall Clow | 4bc2be2 | 2014-02-16 01:57:26 +0000 | [diff] [blame] | 880 | const char *__s = (const char *) __str; |
| 881 | return _VSTD::__put_character_sequence(__os, __s, _Traits::length(__s)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 882 | } |
| 883 | |
| 884 | template <class _CharT, class _Traits> |
| 885 | basic_ostream<_CharT, _Traits>& |
| 886 | basic_ostream<_CharT, _Traits>::put(char_type __c) |
| 887 | { |
| 888 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 889 | try |
| 890 | { |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 891 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 892 | sentry __s(*this); |
| 893 | if (__s) |
| 894 | { |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 895 | typedef ostreambuf_iterator<_CharT, _Traits> _Op; |
| 896 | _Op __o(*this); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 897 | *__o = __c; |
| 898 | if (__o.failed()) |
| 899 | this->setstate(ios_base::badbit); |
| 900 | } |
| 901 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 902 | } |
| 903 | catch (...) |
| 904 | { |
| 905 | this->__set_badbit_and_consider_rethrow(); |
| 906 | } |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 907 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 908 | return *this; |
| 909 | } |
| 910 | |
| 911 | template <class _CharT, class _Traits> |
| 912 | basic_ostream<_CharT, _Traits>& |
| 913 | basic_ostream<_CharT, _Traits>::write(const char_type* __s, streamsize __n) |
| 914 | { |
| 915 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 916 | try |
| 917 | { |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 918 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 919 | sentry __sen(*this); |
| 920 | if (__sen && __n) |
| 921 | { |
Howard Hinnant | 79cef93 | 2013-01-15 17:22:03 +0000 | [diff] [blame] | 922 | if (this->rdbuf()->sputn(__s, __n) != __n) |
| 923 | this->setstate(ios_base::badbit); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 924 | } |
| 925 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 926 | } |
| 927 | catch (...) |
| 928 | { |
| 929 | this->__set_badbit_and_consider_rethrow(); |
| 930 | } |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 931 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 932 | return *this; |
| 933 | } |
| 934 | |
| 935 | template <class _CharT, class _Traits> |
| 936 | basic_ostream<_CharT, _Traits>& |
| 937 | basic_ostream<_CharT, _Traits>::flush() |
| 938 | { |
| 939 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 940 | try |
| 941 | { |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 942 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 943 | if (this->rdbuf()) |
| 944 | { |
| 945 | sentry __s(*this); |
| 946 | if (__s) |
| 947 | { |
| 948 | if (this->rdbuf()->pubsync() == -1) |
| 949 | this->setstate(ios_base::badbit); |
| 950 | } |
| 951 | } |
| 952 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 953 | } |
| 954 | catch (...) |
| 955 | { |
| 956 | this->__set_badbit_and_consider_rethrow(); |
| 957 | } |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 958 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 959 | return *this; |
| 960 | } |
| 961 | |
| 962 | template <class _CharT, class _Traits> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 963 | typename basic_ostream<_CharT, _Traits>::pos_type |
| 964 | basic_ostream<_CharT, _Traits>::tellp() |
| 965 | { |
| 966 | if (this->fail()) |
| 967 | return pos_type(-1); |
| 968 | return this->rdbuf()->pubseekoff(0, ios_base::cur, ios_base::out); |
| 969 | } |
| 970 | |
| 971 | template <class _CharT, class _Traits> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 972 | basic_ostream<_CharT, _Traits>& |
| 973 | basic_ostream<_CharT, _Traits>::seekp(pos_type __pos) |
| 974 | { |
Marshall Clow | 29c4daa | 2013-10-31 22:20:45 +0000 | [diff] [blame] | 975 | sentry __s(*this); |
Marshall Clow | 8aa079a | 2015-06-22 15:01:21 +0000 | [diff] [blame] | 976 | if (!this->fail()) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 977 | { |
| 978 | if (this->rdbuf()->pubseekpos(__pos, ios_base::out) == pos_type(-1)) |
| 979 | this->setstate(ios_base::failbit); |
| 980 | } |
| 981 | return *this; |
| 982 | } |
| 983 | |
| 984 | template <class _CharT, class _Traits> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 985 | basic_ostream<_CharT, _Traits>& |
| 986 | basic_ostream<_CharT, _Traits>::seekp(off_type __off, ios_base::seekdir __dir) |
| 987 | { |
Marshall Clow | 29c4daa | 2013-10-31 22:20:45 +0000 | [diff] [blame] | 988 | sentry __s(*this); |
Marshall Clow | 8aa079a | 2015-06-22 15:01:21 +0000 | [diff] [blame] | 989 | if (!this->fail()) |
Marshall Clow | 29c4daa | 2013-10-31 22:20:45 +0000 | [diff] [blame] | 990 | { |
| 991 | if (this->rdbuf()->pubseekoff(__off, __dir, ios_base::out) == pos_type(-1)) |
| 992 | this->setstate(ios_base::failbit); |
| 993 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 994 | return *this; |
| 995 | } |
| 996 | |
| 997 | template <class _CharT, class _Traits> |
Louis Dionne | e29136f | 2020-07-13 11:53:48 -0400 | [diff] [blame] | 998 | inline |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 999 | basic_ostream<_CharT, _Traits>& |
| 1000 | endl(basic_ostream<_CharT, _Traits>& __os) |
| 1001 | { |
| 1002 | __os.put(__os.widen('\n')); |
| 1003 | __os.flush(); |
| 1004 | return __os; |
| 1005 | } |
| 1006 | |
| 1007 | template <class _CharT, class _Traits> |
Louis Dionne | e29136f | 2020-07-13 11:53:48 -0400 | [diff] [blame] | 1008 | inline |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1009 | basic_ostream<_CharT, _Traits>& |
| 1010 | ends(basic_ostream<_CharT, _Traits>& __os) |
| 1011 | { |
| 1012 | __os.put(_CharT()); |
| 1013 | return __os; |
| 1014 | } |
| 1015 | |
| 1016 | template <class _CharT, class _Traits> |
Louis Dionne | e29136f | 2020-07-13 11:53:48 -0400 | [diff] [blame] | 1017 | inline |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1018 | basic_ostream<_CharT, _Traits>& |
| 1019 | flush(basic_ostream<_CharT, _Traits>& __os) |
| 1020 | { |
| 1021 | __os.flush(); |
| 1022 | return __os; |
| 1023 | } |
| 1024 | |
Louis Dionne | d9f73b1 | 2020-09-23 08:49:00 -0400 | [diff] [blame] | 1025 | template <class _Stream, class _Tp, class = void> |
| 1026 | struct __is_ostreamable : false_type { }; |
| 1027 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1028 | template <class _Stream, class _Tp> |
Louis Dionne | d9f73b1 | 2020-09-23 08:49:00 -0400 | [diff] [blame] | 1029 | struct __is_ostreamable<_Stream, _Tp, decltype( |
Arthur O'Dwyer | 3285c34 | 2021-05-10 13:04:16 -0400 | [diff] [blame] | 1030 | declval<_Stream>() << declval<_Tp>(), void() |
Louis Dionne | d9f73b1 | 2020-09-23 08:49:00 -0400 | [diff] [blame] | 1031 | )> : true_type { }; |
| 1032 | |
| 1033 | template <class _Stream, class _Tp, class = typename enable_if< |
| 1034 | _And<is_base_of<ios_base, _Stream>, |
Arthur O'Dwyer | 46d358c | 2021-06-15 12:57:05 -0400 | [diff] [blame] | 1035 | __is_ostreamable<_Stream&, const _Tp&> >::value |
Louis Dionne | d9f73b1 | 2020-09-23 08:49:00 -0400 | [diff] [blame] | 1036 | >::type> |
| 1037 | _LIBCPP_INLINE_VISIBILITY |
| 1038 | _Stream&& operator<<(_Stream&& __os, const _Tp& __x) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1039 | { |
| 1040 | __os << __x; |
Howard Hinnant | c8697b6 | 2012-01-12 23:37:51 +0000 | [diff] [blame] | 1041 | return _VSTD::move(__os); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1042 | } |
| 1043 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1044 | template<class _CharT, class _Traits, class _Allocator> |
| 1045 | basic_ostream<_CharT, _Traits>& |
| 1046 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 1047 | const basic_string<_CharT, _Traits, _Allocator>& __str) |
| 1048 | { |
Marshall Clow | 4bc2be2 | 2014-02-16 01:57:26 +0000 | [diff] [blame] | 1049 | return _VSTD::__put_character_sequence(__os, __str.data(), __str.size()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1050 | } |
| 1051 | |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 1052 | template<class _CharT, class _Traits> |
| 1053 | basic_ostream<_CharT, _Traits>& |
| 1054 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
Eric Fiselier | 1411692 | 2019-09-25 18:56:54 +0000 | [diff] [blame] | 1055 | basic_string_view<_CharT, _Traits> __sv) |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 1056 | { |
| 1057 | return _VSTD::__put_character_sequence(__os, __sv.data(), __sv.size()); |
| 1058 | } |
| 1059 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1060 | template <class _CharT, class _Traits> |
Evgeniy Stepanov | b925426 | 2016-01-08 19:21:02 +0000 | [diff] [blame] | 1061 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1062 | basic_ostream<_CharT, _Traits>& |
| 1063 | operator<<(basic_ostream<_CharT, _Traits>& __os, const error_code& __ec) |
| 1064 | { |
| 1065 | return __os << __ec.category().name() << ':' << __ec.value(); |
| 1066 | } |
| 1067 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1068 | template<class _CharT, class _Traits, class _Yp> |
Evgeniy Stepanov | b925426 | 2016-01-08 19:21:02 +0000 | [diff] [blame] | 1069 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1070 | basic_ostream<_CharT, _Traits>& |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1071 | operator<<(basic_ostream<_CharT, _Traits>& __os, shared_ptr<_Yp> const& __p) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1072 | { |
| 1073 | return __os << __p.get(); |
| 1074 | } |
| 1075 | |
Marshall Clow | e52a324 | 2017-11-27 15:51:36 +0000 | [diff] [blame] | 1076 | template<class _CharT, class _Traits, class _Yp, class _Dp> |
| 1077 | inline _LIBCPP_INLINE_VISIBILITY |
| 1078 | typename enable_if |
| 1079 | < |
Marshall Clow | eea0a1d | 2018-03-22 18:27:28 +0000 | [diff] [blame] | 1080 | is_same<void, typename __void_t<decltype((declval<basic_ostream<_CharT, _Traits>&>() << declval<typename unique_ptr<_Yp, _Dp>::pointer>()))>::type>::value, |
Marshall Clow | e52a324 | 2017-11-27 15:51:36 +0000 | [diff] [blame] | 1081 | basic_ostream<_CharT, _Traits>& |
| 1082 | >::type |
| 1083 | operator<<(basic_ostream<_CharT, _Traits>& __os, unique_ptr<_Yp, _Dp> const& __p) |
| 1084 | { |
| 1085 | return __os << __p.get(); |
| 1086 | } |
| 1087 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1088 | template <class _CharT, class _Traits, size_t _Size> |
| 1089 | basic_ostream<_CharT, _Traits>& |
Howard Hinnant | fa65ab6 | 2011-04-05 14:55:28 +0000 | [diff] [blame] | 1090 | operator<<(basic_ostream<_CharT, _Traits>& __os, const bitset<_Size>& __x) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1091 | { |
| 1092 | return __os << __x.template to_string<_CharT, _Traits> |
| 1093 | (use_facet<ctype<_CharT> >(__os.getloc()).widen('0'), |
| 1094 | use_facet<ctype<_CharT> >(__os.getloc()).widen('1')); |
| 1095 | } |
| 1096 | |
Eric Fiselier | 1b57fa8 | 2016-09-15 22:27:07 +0000 | [diff] [blame] | 1097 | _LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ostream<char>) |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 1098 | #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS |
Eric Fiselier | 1b57fa8 | 2016-09-15 22:27:07 +0000 | [diff] [blame] | 1099 | _LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ostream<wchar_t>) |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 1100 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1101 | |
| 1102 | _LIBCPP_END_NAMESPACE_STD |
| 1103 | |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 1104 | #endif // _LIBCPP_OSTREAM |