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