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