Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | // -*- C++ -*- |
| 2 | //===-------------------------- ostream -----------------------------------===// |
| 3 | // |
Howard Hinnant | f5256e1 | 2010-05-11 21:36:01 +0000 | [diff] [blame] | 4 | // The LLVM Compiler Infrastructure |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5 | // |
Howard Hinnant | b64f8b0 | 2010-11-16 22:09:02 +0000 | [diff] [blame] | 6 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 7 | // Source Licenses. See LICENSE.TXT for details. |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 8 | // |
| 9 | //===----------------------------------------------------------------------===// |
| 10 | |
| 11 | #ifndef _LIBCPP_OSTREAM |
| 12 | #define _LIBCPP_OSTREAM |
| 13 | |
| 14 | /* |
| 15 | ostream synopsis |
| 16 | |
| 17 | template <class charT, class traits = char_traits<charT> > |
| 18 | class basic_ostream |
| 19 | : virtual public basic_ios<charT,traits> |
| 20 | { |
| 21 | public: |
| 22 | // types (inherited from basic_ios (27.5.4)): |
| 23 | typedef charT char_type; |
| 24 | typedef traits traits_type; |
| 25 | typedef typename traits_type::int_type int_type; |
| 26 | typedef typename traits_type::pos_type pos_type; |
| 27 | typedef typename traits_type::off_type off_type; |
| 28 | |
| 29 | // 27.7.2.2 Constructor/destructor: |
| 30 | explicit basic_ostream(basic_streambuf<char_type,traits>* sb); |
| 31 | basic_ostream(basic_ostream&& rhs); |
| 32 | virtual ~basic_ostream(); |
| 33 | |
| 34 | // 27.7.2.3 Assign/swap |
| 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); |
| 58 | basic_ostream& operator<<(basic_streambuf<char_type,traits>* sb); |
| 59 | |
| 60 | // 27.7.2.7 Unformatted output: |
| 61 | basic_ostream& put(char_type c); |
| 62 | basic_ostream& write(const char_type* s, streamsize n); |
| 63 | basic_ostream& flush(); |
| 64 | |
| 65 | // 27.7.2.5 seeks: |
| 66 | pos_type tellp(); |
| 67 | basic_ostream& seekp(pos_type); |
| 68 | basic_ostream& seekp(off_type, ios_base::seekdir); |
| 69 | }; |
| 70 | |
| 71 | // 27.7.2.6.4 character inserters |
| 72 | |
| 73 | template<class charT, class traits> |
| 74 | basic_ostream<charT,traits>& operator<<(basic_ostream<charT,traits>&, charT); |
| 75 | |
| 76 | template<class charT, class traits> |
| 77 | basic_ostream<charT,traits>& operator<<(basic_ostream<charT,traits>&, char); |
| 78 | |
| 79 | template<class traits> |
| 80 | basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&, char); |
| 81 | |
| 82 | // signed and unsigned |
| 83 | |
| 84 | template<class traits> |
| 85 | basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&, signed char); |
| 86 | |
| 87 | template<class traits> |
| 88 | basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&, unsigned char); |
| 89 | |
| 90 | // NTBS |
| 91 | template<class charT, class traits> |
| 92 | basic_ostream<charT,traits>& operator<<(basic_ostream<charT,traits>&, const charT*); |
| 93 | |
| 94 | template<class charT, class traits> |
| 95 | basic_ostream<charT,traits>& operator<<(basic_ostream<charT,traits>&, const char*); |
| 96 | |
| 97 | template<class traits> |
| 98 | basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&, const char*); |
| 99 | |
| 100 | // signed and unsigned |
| 101 | template<class traits> |
| 102 | basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&, const signed char*); |
| 103 | |
| 104 | template<class traits> |
| 105 | basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&, const unsigned char*); |
| 106 | |
| 107 | // swap: |
| 108 | template <class charT, class traits> |
| 109 | void swap(basic_ostream<charT, traits>& x, basic_ostream<charT, traits>& y); |
| 110 | |
| 111 | template <class charT, class traits> |
| 112 | basic_ostream<charT,traits>& endl(basic_ostream<charT,traits>& os); |
| 113 | |
| 114 | template <class charT, class traits> |
| 115 | basic_ostream<charT,traits>& ends(basic_ostream<charT,traits>& os); |
| 116 | |
| 117 | template <class charT, class traits> |
| 118 | basic_ostream<charT,traits>& flush(basic_ostream<charT,traits>& os); |
| 119 | |
| 120 | // rvalue stream insertion |
| 121 | template <class charT, class traits, class T> |
| 122 | basic_ostream<charT, traits>& |
| 123 | operator<<(basic_ostream<charT, traits>&& os, const T& x); |
| 124 | |
| 125 | } // std |
| 126 | |
| 127 | */ |
| 128 | |
| 129 | #include <__config> |
| 130 | #include <ios> |
| 131 | #include <streambuf> |
| 132 | #include <locale> |
| 133 | #include <iterator> |
| 134 | #include <bitset> |
| 135 | |
Howard Hinnant | 08e1747 | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 136 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 137 | #pragma GCC system_header |
Howard Hinnant | 08e1747 | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 138 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 139 | |
| 140 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 141 | |
| 142 | template <class _CharT, class _Traits> |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 143 | class _LIBCPP_VISIBLE basic_ostream |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 144 | : virtual public basic_ios<_CharT, _Traits> |
| 145 | { |
| 146 | public: |
| 147 | // types (inherited from basic_ios (27.5.4)): |
| 148 | typedef _CharT char_type; |
| 149 | typedef _Traits traits_type; |
| 150 | typedef typename traits_type::int_type int_type; |
| 151 | typedef typename traits_type::pos_type pos_type; |
| 152 | typedef typename traits_type::off_type off_type; |
| 153 | |
| 154 | // 27.7.2.2 Constructor/destructor: |
| 155 | explicit basic_ostream(basic_streambuf<char_type, traits_type>* __sb); |
| 156 | virtual ~basic_ostream(); |
| 157 | protected: |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 158 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | ac6de54 | 2011-07-07 21:03:52 +0000 | [diff] [blame] | 159 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 160 | basic_ostream(basic_ostream&& __rhs); |
| 161 | #endif |
| 162 | |
| 163 | // 27.7.2.3 Assign/swap |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 164 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | ac6de54 | 2011-07-07 21:03:52 +0000 | [diff] [blame] | 165 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 166 | basic_ostream& operator=(basic_ostream&& __rhs); |
| 167 | #endif |
| 168 | void swap(basic_ostream& __rhs); |
| 169 | public: |
| 170 | |
| 171 | // 27.7.2.4 Prefix/suffix: |
Howard Hinnant | 33be35e | 2012-09-14 00:39:16 +0000 | [diff] [blame] | 172 | class _LIBCPP_VISIBLE sentry; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 173 | |
| 174 | // 27.7.2.6 Formatted output: |
| 175 | basic_ostream& operator<<(basic_ostream& (*__pf)(basic_ostream&)); |
| 176 | basic_ostream& operator<<(basic_ios<char_type, traits_type>& |
| 177 | (*__pf)(basic_ios<char_type,traits_type>&)); |
| 178 | basic_ostream& operator<<(ios_base& (*__pf)(ios_base&)); |
| 179 | basic_ostream& operator<<(bool __n); |
| 180 | basic_ostream& operator<<(short __n); |
| 181 | basic_ostream& operator<<(unsigned short __n); |
| 182 | basic_ostream& operator<<(int __n); |
| 183 | basic_ostream& operator<<(unsigned int __n); |
| 184 | basic_ostream& operator<<(long __n); |
| 185 | basic_ostream& operator<<(unsigned long __n); |
| 186 | basic_ostream& operator<<(long long __n); |
| 187 | basic_ostream& operator<<(unsigned long long __n); |
| 188 | basic_ostream& operator<<(float __f); |
| 189 | basic_ostream& operator<<(double __f); |
| 190 | basic_ostream& operator<<(long double __f); |
| 191 | basic_ostream& operator<<(const void* __p); |
| 192 | basic_ostream& operator<<(basic_streambuf<char_type, traits_type>* __sb); |
| 193 | |
| 194 | // 27.7.2.7 Unformatted output: |
| 195 | basic_ostream& put(char_type __c); |
| 196 | basic_ostream& write(const char_type* __s, streamsize __n); |
| 197 | basic_ostream& flush(); |
| 198 | |
| 199 | // 27.7.2.5 seeks: |
| 200 | pos_type tellp(); |
| 201 | basic_ostream& seekp(pos_type __pos); |
| 202 | basic_ostream& seekp(off_type __off, ios_base::seekdir __dir); |
| 203 | |
| 204 | protected: |
| 205 | _LIBCPP_ALWAYS_INLINE |
| 206 | basic_ostream() {} // extension, intentially does not initialize |
| 207 | }; |
| 208 | |
| 209 | template <class _CharT, class _Traits> |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 210 | class _LIBCPP_VISIBLE basic_ostream<_CharT, _Traits>::sentry |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 211 | { |
| 212 | bool __ok_; |
| 213 | basic_ostream<_CharT, _Traits>& __os_; |
| 214 | |
| 215 | sentry(const sentry&); // = delete; |
| 216 | sentry& operator=(const sentry&); // = delete; |
| 217 | |
| 218 | public: |
| 219 | explicit sentry(basic_ostream<_CharT, _Traits>& __os); |
| 220 | ~sentry(); |
| 221 | |
| 222 | _LIBCPP_ALWAYS_INLINE |
Howard Hinnant | 7786188 | 2012-02-21 21:46:43 +0000 | [diff] [blame] | 223 | _LIBCPP_EXPLICIT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 224 | operator bool() const {return __ok_;} |
| 225 | }; |
| 226 | |
| 227 | template <class _CharT, class _Traits> |
| 228 | basic_ostream<_CharT, _Traits>::sentry::sentry(basic_ostream<_CharT, _Traits>& __os) |
| 229 | : __ok_(false), |
| 230 | __os_(__os) |
| 231 | { |
| 232 | if (__os.good()) |
| 233 | { |
| 234 | if (__os.tie()) |
| 235 | __os.tie()->flush(); |
| 236 | __ok_ = true; |
| 237 | } |
| 238 | } |
| 239 | |
| 240 | template <class _CharT, class _Traits> |
| 241 | basic_ostream<_CharT, _Traits>::sentry::~sentry() |
| 242 | { |
| 243 | if (__os_.rdbuf() && __os_.good() && (__os_.flags() & ios_base::unitbuf) |
| 244 | && !uncaught_exception()) |
| 245 | { |
| 246 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 247 | try |
| 248 | { |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 249 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 250 | if (__os_.rdbuf()->pubsync() == -1) |
| 251 | __os_.setstate(ios_base::badbit); |
| 252 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 253 | } |
| 254 | catch (...) |
| 255 | { |
| 256 | } |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 257 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 258 | } |
| 259 | } |
| 260 | |
| 261 | template <class _CharT, class _Traits> |
| 262 | inline _LIBCPP_INLINE_VISIBILITY |
| 263 | basic_ostream<_CharT, _Traits>::basic_ostream(basic_streambuf<char_type, traits_type>* __sb) |
| 264 | { |
| 265 | this->init(__sb); |
| 266 | } |
| 267 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 268 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 269 | |
| 270 | template <class _CharT, class _Traits> |
| 271 | inline _LIBCPP_INLINE_VISIBILITY |
| 272 | basic_ostream<_CharT, _Traits>::basic_ostream(basic_ostream&& __rhs) |
| 273 | { |
| 274 | this->move(__rhs); |
| 275 | } |
| 276 | |
| 277 | template <class _CharT, class _Traits> |
| 278 | inline _LIBCPP_INLINE_VISIBILITY |
| 279 | basic_ostream<_CharT, _Traits>& |
| 280 | basic_ostream<_CharT, _Traits>::operator=(basic_ostream&& __rhs) |
| 281 | { |
| 282 | swap(__rhs); |
| 283 | return *this; |
| 284 | } |
| 285 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 286 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 287 | |
| 288 | template <class _CharT, class _Traits> |
| 289 | basic_ostream<_CharT, _Traits>::~basic_ostream() |
| 290 | { |
| 291 | } |
| 292 | |
| 293 | template <class _CharT, class _Traits> |
| 294 | inline _LIBCPP_INLINE_VISIBILITY |
| 295 | void |
| 296 | basic_ostream<_CharT, _Traits>::swap(basic_ostream& __rhs) |
| 297 | { |
| 298 | basic_ios<char_type, traits_type>::swap(__rhs); |
| 299 | } |
| 300 | |
| 301 | template <class _CharT, class _Traits> |
| 302 | inline _LIBCPP_INLINE_VISIBILITY |
| 303 | basic_ostream<_CharT, _Traits>& |
| 304 | basic_ostream<_CharT, _Traits>::operator<<(basic_ostream& (*__pf)(basic_ostream&)) |
| 305 | { |
| 306 | return __pf(*this); |
| 307 | } |
| 308 | |
| 309 | template <class _CharT, class _Traits> |
| 310 | inline _LIBCPP_INLINE_VISIBILITY |
| 311 | basic_ostream<_CharT, _Traits>& |
| 312 | basic_ostream<_CharT, _Traits>::operator<<(basic_ios<char_type, traits_type>& |
| 313 | (*__pf)(basic_ios<char_type,traits_type>&)) |
| 314 | { |
| 315 | __pf(*this); |
| 316 | return *this; |
| 317 | } |
| 318 | |
| 319 | template <class _CharT, class _Traits> |
| 320 | inline _LIBCPP_INLINE_VISIBILITY |
| 321 | basic_ostream<_CharT, _Traits>& |
| 322 | basic_ostream<_CharT, _Traits>::operator<<(ios_base& (*__pf)(ios_base&)) |
| 323 | { |
| 324 | __pf(*this); |
| 325 | return *this; |
| 326 | } |
| 327 | |
| 328 | template <class _CharT, class _Traits> |
| 329 | basic_ostream<_CharT, _Traits>& |
| 330 | basic_ostream<_CharT, _Traits>::operator<<(basic_streambuf<char_type, traits_type>* __sb) |
| 331 | { |
| 332 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 333 | try |
| 334 | { |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 335 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 336 | sentry __s(*this); |
| 337 | if (__s) |
| 338 | { |
| 339 | if (__sb) |
| 340 | { |
| 341 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 342 | try |
| 343 | { |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 344 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 345 | typedef istreambuf_iterator<_CharT, _Traits> _Ip; |
| 346 | typedef ostreambuf_iterator<_CharT, _Traits> _Op; |
| 347 | _Ip __i(__sb); |
| 348 | _Ip __eof; |
| 349 | _Op __o(*this); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 350 | size_t __c = 0; |
| 351 | for (; __i != __eof; ++__i, ++__o, ++__c) |
| 352 | { |
| 353 | *__o = *__i; |
| 354 | if (__o.failed()) |
| 355 | break; |
| 356 | } |
| 357 | if (__c == 0) |
| 358 | this->setstate(ios_base::failbit); |
| 359 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 360 | } |
| 361 | catch (...) |
| 362 | { |
| 363 | this->__set_failbit_and_consider_rethrow(); |
| 364 | } |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 365 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 366 | } |
| 367 | else |
| 368 | this->setstate(ios_base::badbit); |
| 369 | } |
| 370 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 371 | } |
| 372 | catch (...) |
| 373 | { |
| 374 | this->__set_badbit_and_consider_rethrow(); |
| 375 | } |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 376 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 377 | return *this; |
| 378 | } |
| 379 | |
| 380 | template <class _CharT, class _Traits> |
| 381 | basic_ostream<_CharT, _Traits>& |
| 382 | basic_ostream<_CharT, _Traits>::operator<<(bool __n) |
| 383 | { |
| 384 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 385 | try |
| 386 | { |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 387 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 388 | sentry __s(*this); |
| 389 | if (__s) |
| 390 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 391 | typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp; |
| 392 | const _Fp& __f = use_facet<_Fp>(this->getloc()); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 393 | if (__f.put(*this, *this, this->fill(), __n).failed()) |
| 394 | this->setstate(ios_base::badbit | ios_base::failbit); |
| 395 | } |
| 396 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 397 | } |
| 398 | catch (...) |
| 399 | { |
| 400 | this->__set_badbit_and_consider_rethrow(); |
| 401 | } |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 402 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 403 | return *this; |
| 404 | } |
| 405 | |
| 406 | template <class _CharT, class _Traits> |
| 407 | basic_ostream<_CharT, _Traits>& |
| 408 | basic_ostream<_CharT, _Traits>::operator<<(short __n) |
| 409 | { |
| 410 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 411 | try |
| 412 | { |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 413 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 414 | sentry __s(*this); |
| 415 | if (__s) |
| 416 | { |
| 417 | ios_base::fmtflags __flags = ios_base::flags() & ios_base::basefield; |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 418 | typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp; |
| 419 | const _Fp& __f = use_facet<_Fp>(this->getloc()); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 420 | if (__f.put(*this, *this, this->fill(), |
| 421 | __flags == ios_base::oct || __flags == ios_base::hex ? |
| 422 | static_cast<long>(static_cast<unsigned short>(__n)) : |
| 423 | static_cast<long>(__n)).failed()) |
| 424 | this->setstate(ios_base::badbit | ios_base::failbit); |
| 425 | } |
| 426 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 427 | } |
| 428 | catch (...) |
| 429 | { |
| 430 | this->__set_badbit_and_consider_rethrow(); |
| 431 | } |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 432 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 433 | return *this; |
| 434 | } |
| 435 | |
| 436 | template <class _CharT, class _Traits> |
| 437 | basic_ostream<_CharT, _Traits>& |
| 438 | basic_ostream<_CharT, _Traits>::operator<<(unsigned short __n) |
| 439 | { |
| 440 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 441 | try |
| 442 | { |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 443 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 444 | sentry __s(*this); |
| 445 | if (__s) |
| 446 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 447 | typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp; |
| 448 | const _Fp& __f = use_facet<_Fp>(this->getloc()); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 449 | if (__f.put(*this, *this, this->fill(), static_cast<unsigned long>(__n)).failed()) |
| 450 | this->setstate(ios_base::badbit | ios_base::failbit); |
| 451 | } |
| 452 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 453 | } |
| 454 | catch (...) |
| 455 | { |
| 456 | this->__set_badbit_and_consider_rethrow(); |
| 457 | } |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 458 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 459 | return *this; |
| 460 | } |
| 461 | |
| 462 | template <class _CharT, class _Traits> |
| 463 | basic_ostream<_CharT, _Traits>& |
| 464 | basic_ostream<_CharT, _Traits>::operator<<(int __n) |
| 465 | { |
| 466 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 467 | try |
| 468 | { |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 469 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 470 | sentry __s(*this); |
| 471 | if (__s) |
| 472 | { |
| 473 | ios_base::fmtflags __flags = ios_base::flags() & ios_base::basefield; |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 474 | typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp; |
| 475 | const _Fp& __f = use_facet<_Fp>(this->getloc()); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 476 | if (__f.put(*this, *this, this->fill(), |
| 477 | __flags == ios_base::oct || __flags == ios_base::hex ? |
| 478 | static_cast<long>(static_cast<unsigned int>(__n)) : |
| 479 | static_cast<long>(__n)).failed()) |
| 480 | this->setstate(ios_base::badbit | ios_base::failbit); |
| 481 | } |
| 482 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 483 | } |
| 484 | catch (...) |
| 485 | { |
| 486 | this->__set_badbit_and_consider_rethrow(); |
| 487 | } |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 488 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 489 | return *this; |
| 490 | } |
| 491 | |
| 492 | template <class _CharT, class _Traits> |
| 493 | basic_ostream<_CharT, _Traits>& |
| 494 | basic_ostream<_CharT, _Traits>::operator<<(unsigned int __n) |
| 495 | { |
| 496 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 497 | try |
| 498 | { |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 499 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 500 | sentry __s(*this); |
| 501 | if (__s) |
| 502 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 503 | typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp; |
| 504 | const _Fp& __f = use_facet<_Fp>(this->getloc()); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 505 | if (__f.put(*this, *this, this->fill(), static_cast<unsigned long>(__n)).failed()) |
| 506 | this->setstate(ios_base::badbit | ios_base::failbit); |
| 507 | } |
| 508 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 509 | } |
| 510 | catch (...) |
| 511 | { |
| 512 | this->__set_badbit_and_consider_rethrow(); |
| 513 | } |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 514 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 515 | return *this; |
| 516 | } |
| 517 | |
| 518 | template <class _CharT, class _Traits> |
| 519 | basic_ostream<_CharT, _Traits>& |
| 520 | basic_ostream<_CharT, _Traits>::operator<<(long __n) |
| 521 | { |
| 522 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 523 | try |
| 524 | { |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 525 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 526 | sentry __s(*this); |
| 527 | if (__s) |
| 528 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 529 | typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp; |
| 530 | const _Fp& __f = use_facet<_Fp>(this->getloc()); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 531 | if (__f.put(*this, *this, this->fill(), __n).failed()) |
| 532 | this->setstate(ios_base::badbit | ios_base::failbit); |
| 533 | } |
| 534 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 535 | } |
| 536 | catch (...) |
| 537 | { |
| 538 | this->__set_badbit_and_consider_rethrow(); |
| 539 | } |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 540 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 541 | return *this; |
| 542 | } |
| 543 | |
| 544 | template <class _CharT, class _Traits> |
| 545 | basic_ostream<_CharT, _Traits>& |
| 546 | basic_ostream<_CharT, _Traits>::operator<<(unsigned long __n) |
| 547 | { |
| 548 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 549 | try |
| 550 | { |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 551 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 552 | sentry __s(*this); |
| 553 | if (__s) |
| 554 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 555 | typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp; |
| 556 | const _Fp& __f = use_facet<_Fp>(this->getloc()); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 557 | if (__f.put(*this, *this, this->fill(), __n).failed()) |
| 558 | this->setstate(ios_base::badbit | ios_base::failbit); |
| 559 | } |
| 560 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 561 | } |
| 562 | catch (...) |
| 563 | { |
| 564 | this->__set_badbit_and_consider_rethrow(); |
| 565 | } |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 566 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 567 | return *this; |
| 568 | } |
| 569 | |
| 570 | template <class _CharT, class _Traits> |
| 571 | basic_ostream<_CharT, _Traits>& |
| 572 | basic_ostream<_CharT, _Traits>::operator<<(long long __n) |
| 573 | { |
| 574 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 575 | try |
| 576 | { |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 577 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 578 | sentry __s(*this); |
| 579 | if (__s) |
| 580 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 581 | typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp; |
| 582 | const _Fp& __f = use_facet<_Fp>(this->getloc()); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 583 | if (__f.put(*this, *this, this->fill(), __n).failed()) |
| 584 | this->setstate(ios_base::badbit | ios_base::failbit); |
| 585 | } |
| 586 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 587 | } |
| 588 | catch (...) |
| 589 | { |
| 590 | this->__set_badbit_and_consider_rethrow(); |
| 591 | } |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 592 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 593 | return *this; |
| 594 | } |
| 595 | |
| 596 | template <class _CharT, class _Traits> |
| 597 | basic_ostream<_CharT, _Traits>& |
| 598 | basic_ostream<_CharT, _Traits>::operator<<(unsigned long long __n) |
| 599 | { |
| 600 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 601 | try |
| 602 | { |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 603 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 604 | sentry __s(*this); |
| 605 | if (__s) |
| 606 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 607 | typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp; |
| 608 | const _Fp& __f = use_facet<_Fp>(this->getloc()); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 609 | if (__f.put(*this, *this, this->fill(), __n).failed()) |
| 610 | this->setstate(ios_base::badbit | ios_base::failbit); |
| 611 | } |
| 612 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 613 | } |
| 614 | catch (...) |
| 615 | { |
| 616 | this->__set_badbit_and_consider_rethrow(); |
| 617 | } |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 618 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 619 | return *this; |
| 620 | } |
| 621 | |
| 622 | template <class _CharT, class _Traits> |
| 623 | basic_ostream<_CharT, _Traits>& |
| 624 | basic_ostream<_CharT, _Traits>::operator<<(float __n) |
| 625 | { |
| 626 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 627 | try |
| 628 | { |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 629 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 630 | sentry __s(*this); |
| 631 | if (__s) |
| 632 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 633 | typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp; |
| 634 | const _Fp& __f = use_facet<_Fp>(this->getloc()); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 635 | if (__f.put(*this, *this, this->fill(), static_cast<double>(__n)).failed()) |
| 636 | this->setstate(ios_base::badbit | ios_base::failbit); |
| 637 | } |
| 638 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 639 | } |
| 640 | catch (...) |
| 641 | { |
| 642 | this->__set_badbit_and_consider_rethrow(); |
| 643 | } |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 644 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 645 | return *this; |
| 646 | } |
| 647 | |
| 648 | template <class _CharT, class _Traits> |
| 649 | basic_ostream<_CharT, _Traits>& |
| 650 | basic_ostream<_CharT, _Traits>::operator<<(double __n) |
| 651 | { |
| 652 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 653 | try |
| 654 | { |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 655 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 656 | sentry __s(*this); |
| 657 | if (__s) |
| 658 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 659 | typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp; |
| 660 | const _Fp& __f = use_facet<_Fp>(this->getloc()); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 661 | if (__f.put(*this, *this, this->fill(), __n).failed()) |
| 662 | this->setstate(ios_base::badbit | ios_base::failbit); |
| 663 | } |
| 664 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 665 | } |
| 666 | catch (...) |
| 667 | { |
| 668 | this->__set_badbit_and_consider_rethrow(); |
| 669 | } |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 670 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 671 | return *this; |
| 672 | } |
| 673 | |
| 674 | template <class _CharT, class _Traits> |
| 675 | basic_ostream<_CharT, _Traits>& |
| 676 | basic_ostream<_CharT, _Traits>::operator<<(long double __n) |
| 677 | { |
| 678 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 679 | try |
| 680 | { |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 681 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 682 | sentry __s(*this); |
| 683 | if (__s) |
| 684 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 685 | typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp; |
| 686 | const _Fp& __f = use_facet<_Fp>(this->getloc()); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 687 | if (__f.put(*this, *this, this->fill(), __n).failed()) |
| 688 | this->setstate(ios_base::badbit | ios_base::failbit); |
| 689 | } |
| 690 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 691 | } |
| 692 | catch (...) |
| 693 | { |
| 694 | this->__set_badbit_and_consider_rethrow(); |
| 695 | } |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 696 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 697 | return *this; |
| 698 | } |
| 699 | |
| 700 | template <class _CharT, class _Traits> |
| 701 | basic_ostream<_CharT, _Traits>& |
| 702 | basic_ostream<_CharT, _Traits>::operator<<(const void* __n) |
| 703 | { |
| 704 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 705 | try |
| 706 | { |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 707 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 708 | sentry __s(*this); |
| 709 | if (__s) |
| 710 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 711 | typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp; |
| 712 | const _Fp& __f = use_facet<_Fp>(this->getloc()); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 713 | if (__f.put(*this, *this, this->fill(), __n).failed()) |
| 714 | this->setstate(ios_base::badbit | ios_base::failbit); |
| 715 | } |
| 716 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 717 | } |
| 718 | catch (...) |
| 719 | { |
| 720 | this->__set_badbit_and_consider_rethrow(); |
| 721 | } |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 722 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 723 | return *this; |
| 724 | } |
| 725 | |
| 726 | template<class _CharT, class _Traits> |
| 727 | basic_ostream<_CharT, _Traits>& |
| 728 | operator<<(basic_ostream<_CharT, _Traits>& __os, _CharT __c) |
| 729 | { |
| 730 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 731 | try |
| 732 | { |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 733 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 734 | typename basic_ostream<_CharT, _Traits>::sentry __s(__os); |
| 735 | if (__s) |
| 736 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 737 | typedef ostreambuf_iterator<_CharT, _Traits> _Ip; |
| 738 | if (__pad_and_output(_Ip(__os), |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 739 | &__c, |
| 740 | (__os.flags() & ios_base::adjustfield) == ios_base::left ? |
| 741 | &__c + 1 : |
| 742 | &__c, |
| 743 | &__c + 1, |
| 744 | __os, |
| 745 | __os.fill()).failed()) |
| 746 | __os.setstate(ios_base::badbit | ios_base::failbit); |
| 747 | } |
| 748 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 749 | } |
| 750 | catch (...) |
| 751 | { |
| 752 | __os.__set_badbit_and_consider_rethrow(); |
| 753 | } |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 754 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 755 | return __os; |
| 756 | } |
| 757 | |
| 758 | template<class _CharT, class _Traits> |
| 759 | basic_ostream<_CharT, _Traits>& |
| 760 | operator<<(basic_ostream<_CharT, _Traits>& __os, char __cn) |
| 761 | { |
| 762 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 763 | try |
| 764 | { |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 765 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 766 | typename basic_ostream<_CharT, _Traits>::sentry __s(__os); |
| 767 | if (__s) |
| 768 | { |
| 769 | _CharT __c = __os.widen(__cn); |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 770 | typedef ostreambuf_iterator<_CharT, _Traits> _Ip; |
| 771 | if (__pad_and_output(_Ip(__os), |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 772 | &__c, |
| 773 | (__os.flags() & ios_base::adjustfield) == ios_base::left ? |
| 774 | &__c + 1 : |
| 775 | &__c, |
| 776 | &__c + 1, |
| 777 | __os, |
| 778 | __os.fill()).failed()) |
| 779 | __os.setstate(ios_base::badbit | ios_base::failbit); |
| 780 | } |
| 781 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 782 | } |
| 783 | catch (...) |
| 784 | { |
| 785 | __os.__set_badbit_and_consider_rethrow(); |
| 786 | } |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 787 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 788 | return __os; |
| 789 | } |
| 790 | |
| 791 | template<class _Traits> |
| 792 | basic_ostream<char, _Traits>& |
| 793 | operator<<(basic_ostream<char, _Traits>& __os, char __c) |
| 794 | { |
| 795 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 796 | try |
| 797 | { |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 798 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 799 | typename basic_ostream<char, _Traits>::sentry __s(__os); |
| 800 | if (__s) |
| 801 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 802 | typedef ostreambuf_iterator<char, _Traits> _Ip; |
| 803 | if (__pad_and_output(_Ip(__os), |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 804 | &__c, |
| 805 | (__os.flags() & ios_base::adjustfield) == ios_base::left ? |
| 806 | &__c + 1 : |
| 807 | &__c, |
| 808 | &__c + 1, |
| 809 | __os, |
| 810 | __os.fill()).failed()) |
| 811 | __os.setstate(ios_base::badbit | ios_base::failbit); |
| 812 | } |
| 813 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 814 | } |
| 815 | catch (...) |
| 816 | { |
| 817 | __os.__set_badbit_and_consider_rethrow(); |
| 818 | } |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 819 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 820 | return __os; |
| 821 | } |
| 822 | |
| 823 | template<class _Traits> |
| 824 | basic_ostream<char, _Traits>& |
| 825 | operator<<(basic_ostream<char, _Traits>& __os, signed char __c) |
| 826 | { |
| 827 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 828 | try |
| 829 | { |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 830 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 831 | typename basic_ostream<char, _Traits>::sentry __s(__os); |
| 832 | if (__s) |
| 833 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 834 | typedef ostreambuf_iterator<char, _Traits> _Ip; |
| 835 | if (__pad_and_output(_Ip(__os), |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 836 | (char*)&__c, |
| 837 | (__os.flags() & ios_base::adjustfield) == ios_base::left ? |
| 838 | (char*)&__c + 1 : |
| 839 | (char*)&__c, |
| 840 | (char*)&__c + 1, |
| 841 | __os, |
| 842 | __os.fill()).failed()) |
| 843 | __os.setstate(ios_base::badbit | ios_base::failbit); |
| 844 | } |
| 845 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 846 | } |
| 847 | catch (...) |
| 848 | { |
| 849 | __os.__set_badbit_and_consider_rethrow(); |
| 850 | } |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 851 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 852 | return __os; |
| 853 | } |
| 854 | |
| 855 | template<class _Traits> |
| 856 | basic_ostream<char, _Traits>& |
| 857 | operator<<(basic_ostream<char, _Traits>& __os, unsigned char __c) |
| 858 | { |
| 859 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 860 | try |
| 861 | { |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 862 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 863 | typename basic_ostream<char, _Traits>::sentry __s(__os); |
| 864 | if (__s) |
| 865 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 866 | typedef ostreambuf_iterator<char, _Traits> _Ip; |
| 867 | if (__pad_and_output(_Ip(__os), |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 868 | (char*)&__c, |
| 869 | (__os.flags() & ios_base::adjustfield) == ios_base::left ? |
| 870 | (char*)&__c + 1 : |
| 871 | (char*)&__c, |
| 872 | (char*)&__c + 1, |
| 873 | __os, |
| 874 | __os.fill()).failed()) |
| 875 | __os.setstate(ios_base::badbit | ios_base::failbit); |
| 876 | } |
| 877 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 878 | } |
| 879 | catch (...) |
| 880 | { |
| 881 | __os.__set_badbit_and_consider_rethrow(); |
| 882 | } |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 883 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 884 | return __os; |
| 885 | } |
| 886 | |
| 887 | template<class _CharT, class _Traits> |
| 888 | basic_ostream<_CharT, _Traits>& |
| 889 | operator<<(basic_ostream<_CharT, _Traits>& __os, const _CharT* __str) |
| 890 | { |
| 891 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 892 | try |
| 893 | { |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 894 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 895 | typename basic_ostream<_CharT, _Traits>::sentry __s(__os); |
| 896 | if (__s) |
| 897 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 898 | typedef ostreambuf_iterator<_CharT, _Traits> _Ip; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 899 | size_t __len = _Traits::length(__str); |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 900 | if (__pad_and_output(_Ip(__os), |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 901 | __str, |
| 902 | (__os.flags() & ios_base::adjustfield) == ios_base::left ? |
| 903 | __str + __len : |
| 904 | __str, |
| 905 | __str + __len, |
| 906 | __os, |
| 907 | __os.fill()).failed()) |
| 908 | __os.setstate(ios_base::badbit | ios_base::failbit); |
| 909 | } |
| 910 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 911 | } |
| 912 | catch (...) |
| 913 | { |
| 914 | __os.__set_badbit_and_consider_rethrow(); |
| 915 | } |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 916 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 917 | return __os; |
| 918 | } |
| 919 | |
| 920 | template<class _CharT, class _Traits> |
| 921 | basic_ostream<_CharT, _Traits>& |
| 922 | operator<<(basic_ostream<_CharT, _Traits>& __os, const char* __strn) |
| 923 | { |
| 924 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 925 | try |
| 926 | { |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 927 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 928 | typename basic_ostream<_CharT, _Traits>::sentry __s(__os); |
| 929 | if (__s) |
| 930 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 931 | typedef ostreambuf_iterator<_CharT, _Traits> _Ip; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 932 | size_t __len = char_traits<char>::length(__strn); |
| 933 | const int __bs = 100; |
| 934 | _CharT __wbb[__bs]; |
| 935 | _CharT* __wb = __wbb; |
| 936 | unique_ptr<_CharT, void(*)(void*)> __h(0, free); |
| 937 | if (__len > __bs) |
| 938 | { |
| 939 | __wb = (_CharT*)malloc(__len*sizeof(_CharT)); |
| 940 | if (__wb == 0) |
| 941 | __throw_bad_alloc(); |
| 942 | __h.reset(__wb); |
| 943 | } |
| 944 | for (_CharT* __p = __wb; *__strn != '\0'; ++__strn, ++__p) |
| 945 | *__p = __os.widen(*__strn); |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 946 | if (__pad_and_output(_Ip(__os), |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 947 | __wb, |
| 948 | (__os.flags() & ios_base::adjustfield) == ios_base::left ? |
| 949 | __wb + __len : |
| 950 | __wb, |
| 951 | __wb + __len, |
| 952 | __os, |
| 953 | __os.fill()).failed()) |
| 954 | __os.setstate(ios_base::badbit | ios_base::failbit); |
| 955 | } |
| 956 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 957 | } |
| 958 | catch (...) |
| 959 | { |
| 960 | __os.__set_badbit_and_consider_rethrow(); |
| 961 | } |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 962 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 963 | return __os; |
| 964 | } |
| 965 | |
| 966 | template<class _Traits> |
| 967 | basic_ostream<char, _Traits>& |
| 968 | operator<<(basic_ostream<char, _Traits>& __os, const char* __str) |
| 969 | { |
| 970 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 971 | try |
| 972 | { |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 973 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 974 | typename basic_ostream<char, _Traits>::sentry __s(__os); |
| 975 | if (__s) |
| 976 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 977 | typedef ostreambuf_iterator<char, _Traits> _Ip; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 978 | size_t __len = _Traits::length(__str); |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 979 | if (__pad_and_output(_Ip(__os), |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 980 | __str, |
| 981 | (__os.flags() & ios_base::adjustfield) == ios_base::left ? |
| 982 | __str + __len : |
| 983 | __str, |
| 984 | __str + __len, |
| 985 | __os, |
| 986 | __os.fill()).failed()) |
| 987 | __os.setstate(ios_base::badbit | ios_base::failbit); |
| 988 | } |
| 989 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 990 | } |
| 991 | catch (...) |
| 992 | { |
| 993 | __os.__set_badbit_and_consider_rethrow(); |
| 994 | } |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 995 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 996 | return __os; |
| 997 | } |
| 998 | |
| 999 | template<class _Traits> |
| 1000 | basic_ostream<char, _Traits>& |
| 1001 | operator<<(basic_ostream<char, _Traits>& __os, const signed char* __str) |
| 1002 | { |
| 1003 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1004 | try |
| 1005 | { |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1006 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1007 | typename basic_ostream<char, _Traits>::sentry __s(__os); |
| 1008 | if (__s) |
| 1009 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1010 | typedef ostreambuf_iterator<char, _Traits> _Ip; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1011 | size_t __len = _Traits::length((const char*)__str); |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1012 | if (__pad_and_output(_Ip(__os), |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1013 | (const char*)__str, |
| 1014 | (__os.flags() & ios_base::adjustfield) == ios_base::left ? |
| 1015 | (const char*)__str + __len : |
| 1016 | (const char*)__str, |
| 1017 | (const char*)__str + __len, |
| 1018 | __os, |
| 1019 | __os.fill()).failed()) |
| 1020 | __os.setstate(ios_base::badbit | ios_base::failbit); |
| 1021 | } |
| 1022 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1023 | } |
| 1024 | catch (...) |
| 1025 | { |
| 1026 | __os.__set_badbit_and_consider_rethrow(); |
| 1027 | } |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1028 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1029 | return __os; |
| 1030 | } |
| 1031 | |
| 1032 | template<class _Traits> |
| 1033 | basic_ostream<char, _Traits>& |
| 1034 | operator<<(basic_ostream<char, _Traits>& __os, const unsigned char* __str) |
| 1035 | { |
| 1036 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1037 | try |
| 1038 | { |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1039 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1040 | typename basic_ostream<char, _Traits>::sentry __s(__os); |
| 1041 | if (__s) |
| 1042 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1043 | typedef ostreambuf_iterator<char, _Traits> _Ip; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1044 | size_t __len = _Traits::length((const char*)__str); |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1045 | if (__pad_and_output(_Ip(__os), |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1046 | (const char*)__str, |
| 1047 | (__os.flags() & ios_base::adjustfield) == ios_base::left ? |
| 1048 | (const char*)__str + __len : |
| 1049 | (const char*)__str, |
| 1050 | (const char*)__str + __len, |
| 1051 | __os, |
| 1052 | __os.fill()).failed()) |
| 1053 | __os.setstate(ios_base::badbit | ios_base::failbit); |
| 1054 | } |
| 1055 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1056 | } |
| 1057 | catch (...) |
| 1058 | { |
| 1059 | __os.__set_badbit_and_consider_rethrow(); |
| 1060 | } |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1061 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1062 | return __os; |
| 1063 | } |
| 1064 | |
| 1065 | template <class _CharT, class _Traits> |
| 1066 | basic_ostream<_CharT, _Traits>& |
| 1067 | basic_ostream<_CharT, _Traits>::put(char_type __c) |
| 1068 | { |
| 1069 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1070 | try |
| 1071 | { |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1072 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1073 | sentry __s(*this); |
| 1074 | if (__s) |
| 1075 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1076 | typedef ostreambuf_iterator<_CharT, _Traits> _Op; |
| 1077 | _Op __o(*this); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1078 | *__o = __c; |
| 1079 | if (__o.failed()) |
| 1080 | this->setstate(ios_base::badbit); |
| 1081 | } |
| 1082 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1083 | } |
| 1084 | catch (...) |
| 1085 | { |
| 1086 | this->__set_badbit_and_consider_rethrow(); |
| 1087 | } |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1088 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1089 | return *this; |
| 1090 | } |
| 1091 | |
| 1092 | template <class _CharT, class _Traits> |
| 1093 | basic_ostream<_CharT, _Traits>& |
| 1094 | basic_ostream<_CharT, _Traits>::write(const char_type* __s, streamsize __n) |
| 1095 | { |
| 1096 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1097 | try |
| 1098 | { |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1099 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1100 | sentry __sen(*this); |
| 1101 | if (__sen && __n) |
| 1102 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1103 | typedef ostreambuf_iterator<_CharT, _Traits> _Op; |
| 1104 | _Op __o(*this); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1105 | for (; __n; --__n, ++__o, ++__s) |
| 1106 | { |
| 1107 | *__o = *__s; |
| 1108 | if (__o.failed()) |
| 1109 | { |
| 1110 | this->setstate(ios_base::badbit); |
| 1111 | break; |
| 1112 | } |
| 1113 | } |
| 1114 | } |
| 1115 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1116 | } |
| 1117 | catch (...) |
| 1118 | { |
| 1119 | this->__set_badbit_and_consider_rethrow(); |
| 1120 | } |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1121 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1122 | return *this; |
| 1123 | } |
| 1124 | |
| 1125 | template <class _CharT, class _Traits> |
| 1126 | basic_ostream<_CharT, _Traits>& |
| 1127 | basic_ostream<_CharT, _Traits>::flush() |
| 1128 | { |
| 1129 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1130 | try |
| 1131 | { |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1132 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1133 | if (this->rdbuf()) |
| 1134 | { |
| 1135 | sentry __s(*this); |
| 1136 | if (__s) |
| 1137 | { |
| 1138 | if (this->rdbuf()->pubsync() == -1) |
| 1139 | this->setstate(ios_base::badbit); |
| 1140 | } |
| 1141 | } |
| 1142 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1143 | } |
| 1144 | catch (...) |
| 1145 | { |
| 1146 | this->__set_badbit_and_consider_rethrow(); |
| 1147 | } |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1148 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1149 | return *this; |
| 1150 | } |
| 1151 | |
| 1152 | template <class _CharT, class _Traits> |
| 1153 | inline _LIBCPP_INLINE_VISIBILITY |
| 1154 | typename basic_ostream<_CharT, _Traits>::pos_type |
| 1155 | basic_ostream<_CharT, _Traits>::tellp() |
| 1156 | { |
| 1157 | if (this->fail()) |
| 1158 | return pos_type(-1); |
| 1159 | return this->rdbuf()->pubseekoff(0, ios_base::cur, ios_base::out); |
| 1160 | } |
| 1161 | |
| 1162 | template <class _CharT, class _Traits> |
| 1163 | inline _LIBCPP_INLINE_VISIBILITY |
| 1164 | basic_ostream<_CharT, _Traits>& |
| 1165 | basic_ostream<_CharT, _Traits>::seekp(pos_type __pos) |
| 1166 | { |
| 1167 | if (!this->fail()) |
| 1168 | { |
| 1169 | if (this->rdbuf()->pubseekpos(__pos, ios_base::out) == pos_type(-1)) |
| 1170 | this->setstate(ios_base::failbit); |
| 1171 | } |
| 1172 | return *this; |
| 1173 | } |
| 1174 | |
| 1175 | template <class _CharT, class _Traits> |
| 1176 | inline _LIBCPP_INLINE_VISIBILITY |
| 1177 | basic_ostream<_CharT, _Traits>& |
| 1178 | basic_ostream<_CharT, _Traits>::seekp(off_type __off, ios_base::seekdir __dir) |
| 1179 | { |
| 1180 | if (!this->fail()) |
| 1181 | this->rdbuf()->pubseekoff(__off, __dir, ios_base::out); |
| 1182 | return *this; |
| 1183 | } |
| 1184 | |
| 1185 | template <class _CharT, class _Traits> |
| 1186 | inline _LIBCPP_INLINE_VISIBILITY |
| 1187 | basic_ostream<_CharT, _Traits>& |
| 1188 | endl(basic_ostream<_CharT, _Traits>& __os) |
| 1189 | { |
| 1190 | __os.put(__os.widen('\n')); |
| 1191 | __os.flush(); |
| 1192 | return __os; |
| 1193 | } |
| 1194 | |
| 1195 | template <class _CharT, class _Traits> |
| 1196 | inline _LIBCPP_INLINE_VISIBILITY |
| 1197 | basic_ostream<_CharT, _Traits>& |
| 1198 | ends(basic_ostream<_CharT, _Traits>& __os) |
| 1199 | { |
| 1200 | __os.put(_CharT()); |
| 1201 | return __os; |
| 1202 | } |
| 1203 | |
| 1204 | template <class _CharT, class _Traits> |
| 1205 | inline _LIBCPP_INLINE_VISIBILITY |
| 1206 | basic_ostream<_CharT, _Traits>& |
| 1207 | flush(basic_ostream<_CharT, _Traits>& __os) |
| 1208 | { |
| 1209 | __os.flush(); |
| 1210 | return __os; |
| 1211 | } |
| 1212 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1213 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1214 | |
| 1215 | template <class _Stream, class _Tp> |
| 1216 | inline _LIBCPP_INLINE_VISIBILITY |
| 1217 | typename enable_if |
| 1218 | < |
| 1219 | !is_lvalue_reference<_Stream>::value && |
| 1220 | is_base_of<ios_base, _Stream>::value, |
Howard Hinnant | e1a7b04 | 2012-01-12 23:37:51 +0000 | [diff] [blame] | 1221 | _Stream&& |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1222 | >::type |
| 1223 | operator<<(_Stream&& __os, const _Tp& __x) |
| 1224 | { |
| 1225 | __os << __x; |
Howard Hinnant | e1a7b04 | 2012-01-12 23:37:51 +0000 | [diff] [blame] | 1226 | return _VSTD::move(__os); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1227 | } |
| 1228 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1229 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1230 | |
| 1231 | template<class _CharT, class _Traits, class _Allocator> |
| 1232 | basic_ostream<_CharT, _Traits>& |
| 1233 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 1234 | const basic_string<_CharT, _Traits, _Allocator>& __str) |
| 1235 | { |
| 1236 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1237 | try |
| 1238 | { |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1239 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1240 | typename basic_ostream<_CharT, _Traits>::sentry __s(__os); |
| 1241 | if (__s) |
| 1242 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1243 | typedef ostreambuf_iterator<_CharT, _Traits> _Ip; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1244 | size_t __len = __str.size(); |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1245 | if (__pad_and_output(_Ip(__os), |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1246 | __str.data(), |
| 1247 | (__os.flags() & ios_base::adjustfield) == ios_base::left ? |
| 1248 | __str.data() + __len : |
| 1249 | __str.data(), |
| 1250 | __str.data() + __len, |
| 1251 | __os, |
| 1252 | __os.fill()).failed()) |
| 1253 | __os.setstate(ios_base::badbit | ios_base::failbit); |
| 1254 | } |
| 1255 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1256 | } |
| 1257 | catch (...) |
| 1258 | { |
| 1259 | __os.__set_badbit_and_consider_rethrow(); |
| 1260 | } |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1261 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1262 | return __os; |
| 1263 | } |
| 1264 | |
| 1265 | template <class _CharT, class _Traits> |
| 1266 | inline _LIBCPP_INLINE_VISIBILITY |
| 1267 | basic_ostream<_CharT, _Traits>& |
| 1268 | operator<<(basic_ostream<_CharT, _Traits>& __os, const error_code& __ec) |
| 1269 | { |
| 1270 | return __os << __ec.category().name() << ':' << __ec.value(); |
| 1271 | } |
| 1272 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1273 | template<class _CharT, class _Traits, class _Yp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1274 | inline _LIBCPP_INLINE_VISIBILITY |
| 1275 | basic_ostream<_CharT, _Traits>& |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1276 | operator<<(basic_ostream<_CharT, _Traits>& __os, shared_ptr<_Yp> const& __p) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1277 | { |
| 1278 | return __os << __p.get(); |
| 1279 | } |
| 1280 | |
| 1281 | template <class _CharT, class _Traits, size_t _Size> |
| 1282 | basic_ostream<_CharT, _Traits>& |
Howard Hinnant | a02851e | 2011-04-05 14:55:28 +0000 | [diff] [blame] | 1283 | operator<<(basic_ostream<_CharT, _Traits>& __os, const bitset<_Size>& __x) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1284 | { |
| 1285 | return __os << __x.template to_string<_CharT, _Traits> |
| 1286 | (use_facet<ctype<_CharT> >(__os.getloc()).widen('0'), |
| 1287 | use_facet<ctype<_CharT> >(__os.getloc()).widen('1')); |
| 1288 | } |
| 1289 | |
| 1290 | extern template class basic_ostream<char>; |
| 1291 | extern template class basic_ostream<wchar_t>; |
| 1292 | |
| 1293 | _LIBCPP_END_NAMESPACE_STD |
| 1294 | |
| 1295 | #endif // _LIBCPP_OSTREAM |