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