| 1 | // -*- C++ -*- |
| 2 | //===----------------------------------------------------------------------===// |
| 3 | // |
| 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 |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #ifndef _LIBCPP_SSTREAM |
| 11 | #define _LIBCPP_SSTREAM |
| 12 | |
| 13 | // clang-format off |
| 14 | |
| 15 | /* |
| 16 | sstream synopsis [sstream.syn] |
| 17 | |
| 18 | // Class template basic_stringbuf [stringbuf] |
| 19 | template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> > |
| 20 | class basic_stringbuf |
| 21 | : public basic_streambuf<charT, traits> |
| 22 | { |
| 23 | public: |
| 24 | typedef charT char_type; |
| 25 | typedef traits traits_type; |
| 26 | typedef typename traits_type::int_type int_type; |
| 27 | typedef typename traits_type::pos_type pos_type; |
| 28 | typedef typename traits_type::off_type off_type; |
| 29 | typedef Allocator allocator_type; |
| 30 | |
| 31 | // [stringbuf.cons] constructors: |
| 32 | explicit basic_stringbuf(ios_base::openmode which = ios_base::in | ios_base::out); // before C++20 |
| 33 | basic_stringbuf() : basic_stringbuf(ios_base::in | ios_base::out) {} // C++20 |
| 34 | explicit basic_stringbuf(ios_base::openmode which); // C++20 |
| 35 | explicit basic_stringbuf(const basic_string<char_type, traits_type, allocator_type>& s, |
| 36 | ios_base::openmode which = ios_base::in | ios_base::out); |
| 37 | explicit basic_stringbuf(const allocator_type& a) |
| 38 | : basic_stringbuf(ios_base::in | ios_base::out, a) {} // C++20 |
| 39 | basic_stringbuf(ios_base::openmode which, const allocator_type& a); // C++20 |
| 40 | explicit basic_stringbuf(basic_string<char_type, traits_type, allocator_type>&& s, |
| 41 | ios_base::openmode which = ios_base::in | ios_base::out); // C++20 |
| 42 | template <class SAlloc> |
| 43 | basic_stringbuf(const basic_string<char_type, traits_type, SAlloc>& s, const allocator_type& a) |
| 44 | : basic_stringbuf(s, ios_base::in | ios_base::out, a) {} // C++20 |
| 45 | template <class SAlloc> |
| 46 | basic_stringbuf(const basic_string<char_type, traits_type, SAlloc>& s, |
| 47 | ios_base::openmode which, const allocator_type& a); // C++20 |
| 48 | template <class SAlloc> |
| 49 | explicit basic_stringbuf(const basic_string<char_type, traits_type, SAlloc>& s, |
| 50 | ios_base::openmode which = ios_base::in | ios_base::out); // C++20 |
| 51 | template<class T> |
| 52 | explicit basic_stringbuf(const T& t, |
| 53 | ios_base::openmode which = ios_base::in | ios_base::out); // Since C++26 |
| 54 | template<class T> |
| 55 | basic_stringbuf(const T& t, const Allocator& a); // Since C++26 |
| 56 | template<class T> |
| 57 | basic_stringbuf(const T& t, ios_base::openmode which, const Allocator& a); // Since C++26 |
| 58 | basic_stringbuf(const basic_stringbuf&) = delete; |
| 59 | basic_stringbuf(basic_stringbuf&& rhs); |
| 60 | basic_stringbuf(basic_stringbuf&& rhs, const allocator_type& a); // C++20 |
| 61 | |
| 62 | // [stringbuf.assign] Assign and swap: |
| 63 | basic_stringbuf& operator=(const basic_stringbuf&) = delete; |
| 64 | basic_stringbuf& operator=(basic_stringbuf&& rhs); |
| 65 | void swap(basic_stringbuf& rhs) noexcept(see below); // conditionally noexcept since C++20 |
| 66 | |
| 67 | // [stringbuf.members] Member functions: |
| 68 | allocator_type get_allocator() const noexcept; // C++20 |
| 69 | basic_string<char_type, traits_type, allocator_type> str() const; // before C++20 |
| 70 | basic_string<char_type, traits_type, allocator_type> str() const &; // C++20 |
| 71 | template <class SAlloc> |
| 72 | basic_string<char_type, traits_type, SAlloc> str(const SAlloc& sa) const; // C++20 |
| 73 | basic_string<char_type, traits_type, allocator_type> str() &&; // C++20 |
| 74 | basic_string_view<char_type, traits_type> view() const noexcept; // C++20 |
| 75 | void str(const basic_string<char_type, traits_type, allocator_type>& s); |
| 76 | template <class SAlloc> |
| 77 | void str(const basic_string<char_type, traits_type, SAlloc>& s); // C++20 |
| 78 | void str(basic_string<char_type, traits_type, allocator_type>&& s); // C++20 |
| 79 | template<class T> |
| 80 | void str(const T& t); // Since C++26 |
| 81 | |
| 82 | protected: |
| 83 | // [stringbuf.virtuals] Overridden virtual functions: |
| 84 | virtual int_type underflow(); |
| 85 | virtual int_type pbackfail(int_type c = traits_type::eof()); |
| 86 | virtual int_type overflow (int_type c = traits_type::eof()); |
| 87 | virtual basic_streambuf<char_type, traits_type>* setbuf(char_type*, streamsize); |
| 88 | virtual pos_type seekoff(off_type off, ios_base::seekdir way, |
| 89 | ios_base::openmode which = ios_base::in | ios_base::out); |
| 90 | virtual pos_type seekpos(pos_type sp, |
| 91 | ios_base::openmode which = ios_base::in | ios_base::out); |
| 92 | }; |
| 93 | |
| 94 | // [stringbuf.assign] non member swap |
| 95 | template <class charT, class traits, class Allocator> |
| 96 | void swap(basic_stringbuf<charT, traits, Allocator>& x, |
| 97 | basic_stringbuf<charT, traits, Allocator>& y); // conditionally noexcept since C++20 |
| 98 | |
| 99 | typedef basic_stringbuf<char> stringbuf; |
| 100 | typedef basic_stringbuf<wchar_t> wstringbuf; |
| 101 | |
| 102 | // Class template basic_istringstream [istringstream] |
| 103 | template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> > |
| 104 | class basic_istringstream |
| 105 | : public basic_istream<charT, traits> |
| 106 | { |
| 107 | public: |
| 108 | typedef charT char_type; |
| 109 | typedef traits traits_type; |
| 110 | typedef typename traits_type::int_type int_type; |
| 111 | typedef typename traits_type::pos_type pos_type; |
| 112 | typedef typename traits_type::off_type off_type; |
| 113 | typedef Allocator allocator_type; |
| 114 | |
| 115 | // [istringstream.cons] Constructors: |
| 116 | explicit basic_istringstream(ios_base::openmode which = ios_base::in); // before C++20 |
| 117 | basic_istringstream() : basic_istringstream(ios_base::in) {} // C++20 |
| 118 | explicit basic_istringstream(ios_base::openmode which); // C++20 |
| 119 | explicit basic_istringstream(const basic_string<char_type, traits_type, allocator_type>& s, |
| 120 | ios_base::openmode which = ios_base::in); |
| 121 | basic_istringstream(ios_base::openmode which, const allocator_type& a); // C++20 |
| 122 | explicit basic_istringstream(basic_string<char_type, traits_type, allocator_type>&& s, |
| 123 | ios_base::openmode which = ios_base::in); // C++20 |
| 124 | template <class SAlloc> |
| 125 | basic_istringstream(const basic_string<char_type, traits_type, SAlloc>& s, const allocator_type& a) |
| 126 | : basic_istringstream(s, ios_base::in, a) {} // C++20 |
| 127 | template <class SAlloc> |
| 128 | basic_istringstream(const basic_string<char_type, traits_type, SAlloc>& s, |
| 129 | ios_base::openmode which, const allocator_type& a); // C++20 |
| 130 | template <class SAlloc> |
| 131 | explicit basic_istringstream(const basic_string<char_type, traits_type, SAlloc>& s, |
| 132 | ios_base::openmode which = ios_base::in); // C++20 |
| 133 | template<class T> |
| 134 | explicit basic_istringstream(const T& t, ios_base::openmode which = ios_base::in); // Since C++26 |
| 135 | template<class T> |
| 136 | basic_istringstream(const T& t, const Allocator& a); // Since C++26 |
| 137 | template<class T> |
| 138 | basic_istringstream(const T& t, ios_base::openmode which, const Allocator& a); // Since C++26 |
| 139 | basic_istringstream(const basic_istringstream&) = delete; |
| 140 | basic_istringstream(basic_istringstream&& rhs); |
| 141 | |
| 142 | // [istringstream.assign] Assign and swap: |
| 143 | basic_istringstream& operator=(const basic_istringstream&) = delete; |
| 144 | basic_istringstream& operator=(basic_istringstream&& rhs); |
| 145 | void swap(basic_istringstream& rhs); |
| 146 | |
| 147 | // [istringstream.members] Member functions: |
| 148 | basic_stringbuf<char_type, traits_type, allocator_type>* rdbuf() const; |
| 149 | basic_string<char_type, traits_type, allocator_type> str() const; // before C++20 |
| 150 | basic_string<char_type, traits_type, allocator_type> str() const &; // C++20 |
| 151 | template <class SAlloc> |
| 152 | basic_string<char_type, traits_type, SAlloc> str(const SAlloc& sa) const; // C++20 |
| 153 | basic_string<char_type, traits_type, allocator_type> str() &&; // C++20 |
| 154 | basic_string_view<char_type, traits_type> view() const noexcept; // C++20 |
| 155 | void str(const basic_string<char_type, traits_type, allocator_type>& s); |
| 156 | template <class SAlloc> |
| 157 | void str(const basic_string<char_type, traits_type, SAlloc>& s); // C++20 |
| 158 | void str(basic_string<char_type, traits_type, allocator_type>&& s); // C++20 |
| 159 | template<class T> |
| 160 | void str(const T& t); // Since C++26 |
| 161 | }; |
| 162 | |
| 163 | template <class charT, class traits, class Allocator> |
| 164 | void swap(basic_istringstream<charT, traits, Allocator>& x, |
| 165 | basic_istringstream<charT, traits, Allocator>& y); |
| 166 | |
| 167 | typedef basic_istringstream<char> istringstream; |
| 168 | typedef basic_istringstream<wchar_t> wistringstream; |
| 169 | |
| 170 | // Class template basic_ostringstream [ostringstream] |
| 171 | template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> > |
| 172 | class basic_ostringstream |
| 173 | : public basic_ostream<charT, traits> |
| 174 | { |
| 175 | public: |
| 176 | // types: |
| 177 | typedef charT char_type; |
| 178 | typedef traits traits_type; |
| 179 | typedef typename traits_type::int_type int_type; |
| 180 | typedef typename traits_type::pos_type pos_type; |
| 181 | typedef typename traits_type::off_type off_type; |
| 182 | typedef Allocator allocator_type; |
| 183 | |
| 184 | // [ostringstream.cons] Constructors: |
| 185 | explicit basic_ostringstream(ios_base::openmode which = ios_base::out); // before C++20 |
| 186 | basic_ostringstream() : basic_ostringstream(ios_base::out) {} // C++20 |
| 187 | explicit basic_ostringstream(ios_base::openmode which); // C++20 |
| 188 | explicit basic_ostringstream(const basic_string<char_type, traits_type, allocator_type>& s, |
| 189 | ios_base::openmode which = ios_base::out); |
| 190 | basic_ostringstream(ios_base::openmode which, const allocator_type& a); // C++20 |
| 191 | explicit basic_ostringstream(basic_string<char_type, traits_type, allocator_type>&& s, |
| 192 | ios_base::openmode which = ios_base::out); // C++20 |
| 193 | template <class SAlloc> |
| 194 | basic_ostringstream(const basic_string<char_type, traits_type, SAlloc>& s, const allocator_type& a) |
| 195 | : basic_ostringstream(s, ios_base::out, a) {} // C++20 |
| 196 | template <class SAlloc> |
| 197 | basic_ostringstream(const basic_string<char_type, traits_type, SAlloc>& s, |
| 198 | ios_base::openmode which, const allocator_type& a); // C++20 |
| 199 | template <class SAlloc> |
| 200 | explicit basic_ostringstream(const basic_string<char_type, traits_type, SAlloc>& s, |
| 201 | ios_base::openmode which = ios_base::out); // C++20 |
| 202 | template<class T> |
| 203 | explicit basic_ostringstream(const T& t, ios_base::openmode which = ios_base::out); // Since C++26 |
| 204 | template<class T> |
| 205 | basic_ostringstream(const T& t, const Allocator& a); // Since C++26 |
| 206 | template<class T> |
| 207 | basic_ostringstream(const T& t, ios_base::openmode which, const Allocator& a); // Since C++26 |
| 208 | basic_ostringstream(const basic_ostringstream&) = delete; |
| 209 | basic_ostringstream(basic_ostringstream&& rhs); |
| 210 | |
| 211 | // [ostringstream.assign] Assign and swap: |
| 212 | basic_ostringstream& operator=(const basic_ostringstream&) = delete; |
| 213 | basic_ostringstream& operator=(basic_ostringstream&& rhs); |
| 214 | void swap(basic_ostringstream& rhs); |
| 215 | |
| 216 | // [ostringstream.members] Member functions: |
| 217 | basic_stringbuf<char_type, traits_type, allocator_type>* rdbuf() const; |
| 218 | basic_string<char_type, traits_type, allocator_type> str() const; // before C++20 |
| 219 | basic_string<char_type, traits_type, allocator_type> str() const &; // C++20 |
| 220 | template <class SAlloc> |
| 221 | basic_string<char_type, traits_type, SAlloc> str(const SAlloc& sa) const; // C++20 |
| 222 | basic_string<char_type, traits_type, allocator_type> str() &&; // C++20 |
| 223 | basic_string_view<char_type, traits_type> view() const noexcept; // C++20 |
| 224 | void str(const basic_string<char_type, traits_type, allocator_type>& s); |
| 225 | template <class SAlloc> |
| 226 | void str(const basic_string<char_type, traits_type, SAlloc>& s); // C++20 |
| 227 | void str(basic_string<char_type, traits_type, allocator_type>&& s); // C++20 |
| 228 | template<class T> |
| 229 | void str(const T& t); // Since C++26 |
| 230 | }; |
| 231 | |
| 232 | template <class charT, class traits, class Allocator> |
| 233 | void swap(basic_ostringstream<charT, traits, Allocator>& x, |
| 234 | basic_ostringstream<charT, traits, Allocator>& y); |
| 235 | |
| 236 | typedef basic_ostringstream<char> ostringstream; |
| 237 | typedef basic_ostringstream<wchar_t> wostringstream; |
| 238 | |
| 239 | // Class template basic_stringstream [stringstream] |
| 240 | template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> > |
| 241 | class basic_stringstream |
| 242 | : public basic_iostream<charT, traits> |
| 243 | { |
| 244 | public: |
| 245 | // types: |
| 246 | typedef charT char_type; |
| 247 | typedef traits traits_type; |
| 248 | typedef typename traits_type::int_type int_type; |
| 249 | typedef typename traits_type::pos_type pos_type; |
| 250 | typedef typename traits_type::off_type off_type; |
| 251 | typedef Allocator allocator_type; |
| 252 | |
| 253 | // [stringstream.cons] constructors |
| 254 | explicit basic_stringstream(ios_base::openmode which = ios_base::out | ios_base::in); // before C++20 |
| 255 | basic_stringstream() : basic_stringstream(ios_base::out | ios_base::in) {} // C++20 |
| 256 | explicit basic_stringstream(ios_base::openmode which); // C++20 |
| 257 | explicit basic_stringstream(const basic_string<char_type, traits_type, allocator_type>& s, |
| 258 | ios_base::openmode which = ios_base::out | ios_base::in); |
| 259 | basic_stringstream(ios_base::openmode which, const allocator_type& a); // C++20 |
| 260 | explicit basic_stringstream(basic_string<char_type, traits_type, allocator_type>&& s, |
| 261 | ios_base::openmode which = ios_base::out | ios_base::in); // C++20 |
| 262 | template <class SAlloc> |
| 263 | basic_stringstream(const basic_string<char_type, traits_type, SAlloc>& s, const allocator_type& a) |
| 264 | : basic_stringstream(s, ios_base::out | ios_base::in, a) {} // C++20 |
| 265 | template <class SAlloc> |
| 266 | basic_stringstream(const basic_string<char_type, traits_type, SAlloc>& s, |
| 267 | ios_base::openmode which, const allocator_type& a); // C++20 |
| 268 | template <class SAlloc> |
| 269 | explicit basic_stringstream(const basic_string<char_type, traits_type, SAlloc>& s, |
| 270 | ios_base::openmode which = ios_base::out | ios_base::in); // C++20 |
| 271 | template<class T> |
| 272 | explicit basic_stringstream(const T& t, |
| 273 | ios_base::openmode which = ios_base::out | ios_base::in); // Since C++26 |
| 274 | template<class T> |
| 275 | basic_stringstream(const T& t, const Allocator& a); // Since C++26 |
| 276 | template<class T> |
| 277 | basic_stringstream(const T& t, ios_base::openmode which, const Allocator& a); // Since C++26 |
| 278 | basic_stringstream(const basic_stringstream&) = delete; |
| 279 | basic_stringstream(basic_stringstream&& rhs); |
| 280 | |
| 281 | // [stringstream.assign] Assign and swap: |
| 282 | basic_stringstream& operator=(const basic_stringstream&) = delete; |
| 283 | basic_stringstream& operator=(basic_stringstream&& rhs); |
| 284 | void swap(basic_stringstream& rhs); |
| 285 | |
| 286 | // [stringstream.members] Member functions: |
| 287 | basic_stringbuf<char_type, traits_type, allocator_type>* rdbuf() const; |
| 288 | basic_string<char_type, traits_type, allocator_type> str() const; // before C++20 |
| 289 | basic_string<char_type, traits_type, allocator_type> str() const &; // C++20 |
| 290 | template <class SAlloc> |
| 291 | basic_string<char_type, traits_type, SAlloc> str(const SAlloc& sa) const; // C++20 |
| 292 | basic_string<char_type, traits_type, allocator_type> str() &&; // C++20 |
| 293 | basic_string_view<char_type, traits_type> view() const noexcept; // C++20 |
| 294 | void str(const basic_string<char_type, traits_type, allocator_type>& s); |
| 295 | template <class SAlloc> |
| 296 | void str(const basic_string<char_type, traits_type, SAlloc>& s); // C++20 |
| 297 | void str(basic_string<char_type, traits_type, allocator_type>&& s); // C++20 |
| 298 | template<class T> |
| 299 | void str(const T& t); // Since C++26 |
| 300 | }; |
| 301 | |
| 302 | template <class charT, class traits, class Allocator> |
| 303 | void swap(basic_stringstream<charT, traits, Allocator>& x, |
| 304 | basic_stringstream<charT, traits, Allocator>& y); |
| 305 | |
| 306 | typedef basic_stringstream<char> stringstream; |
| 307 | typedef basic_stringstream<wchar_t> wstringstream; |
| 308 | |
| 309 | } // std |
| 310 | |
| 311 | */ |
| 312 | |
| 313 | // clang-format on |
| 314 | |
| 315 | #if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS) |
| 316 | # include <__cxx03/sstream> |
| 317 | #else |
| 318 | # include <__config> |
| 319 | |
| 320 | # if _LIBCPP_HAS_LOCALIZATION |
| 321 | |
| 322 | # include <__fwd/sstream.h> |
| 323 | # include <__ostream/basic_ostream.h> |
| 324 | # include <__type_traits/is_convertible.h> |
| 325 | # include <__utility/swap.h> |
| 326 | # include <ios> |
| 327 | # include <istream> |
| 328 | # include <locale> |
| 329 | # include <string> |
| 330 | # include <string_view> |
| 331 | # include <version> |
| 332 | |
| 333 | # if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
| 334 | # pragma GCC system_header |
| 335 | # endif |
| 336 | |
| 337 | _LIBCPP_PUSH_MACROS |
| 338 | # include <__undef_macros> |
| 339 | |
| 340 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 341 | |
| 342 | // Class template basic_stringbuf [stringbuf] |
| 343 | |
| 344 | template <class _CharT, class _Traits, class _Allocator> |
| 345 | class basic_stringbuf : public basic_streambuf<_CharT, _Traits> { |
| 346 | public: |
| 347 | typedef _CharT char_type; |
| 348 | typedef _Traits traits_type; |
| 349 | typedef typename traits_type::int_type int_type; |
| 350 | typedef typename traits_type::pos_type pos_type; |
| 351 | typedef typename traits_type::off_type off_type; |
| 352 | typedef _Allocator allocator_type; |
| 353 | |
| 354 | typedef basic_string<char_type, traits_type, allocator_type> string_type; |
| 355 | |
| 356 | private: |
| 357 | string_type __str_; |
| 358 | mutable char_type* __hm_; |
| 359 | ios_base::openmode __mode_; |
| 360 | _LIBCPP_HIDE_FROM_ABI void __init_buf_ptrs(); |
| 361 | _LIBCPP_HIDE_FROM_ABI void __move_init(basic_stringbuf&& __rhs); |
| 362 | |
| 363 | public: |
| 364 | // [stringbuf.cons] constructors: |
| 365 | _LIBCPP_HIDE_FROM_ABI basic_stringbuf() : __hm_(nullptr), __mode_(ios_base::in | ios_base::out) { |
| 366 | // it is implementation-defined whether we initialize eback() & friends to nullptr, and libc++ doesn't |
| 367 | __init_buf_ptrs(); |
| 368 | } |
| 369 | |
| 370 | _LIBCPP_HIDE_FROM_ABI explicit basic_stringbuf(ios_base::openmode __wch) : __hm_(nullptr), __mode_(__wch) { |
| 371 | // it is implementation-defined whether we initialize eback() & friends to nullptr, and libc++ doesn't |
| 372 | __init_buf_ptrs(); |
| 373 | } |
| 374 | |
| 375 | _LIBCPP_HIDE_FROM_ABI explicit basic_stringbuf(const string_type& __s, |
| 376 | ios_base::openmode __wch = ios_base::in | ios_base::out) |
| 377 | : __str_(__s.get_allocator()), __hm_(nullptr), __mode_(__wch) { |
| 378 | str(__s); |
| 379 | } |
| 380 | |
| 381 | # if _LIBCPP_STD_VER >= 20 |
| 382 | _LIBCPP_HIDE_FROM_ABI explicit basic_stringbuf(const allocator_type& __a) |
| 383 | : basic_stringbuf(ios_base::in | ios_base::out, __a) {} |
| 384 | |
| 385 | _LIBCPP_HIDE_FROM_ABI basic_stringbuf(ios_base::openmode __wch, const allocator_type& __a) |
| 386 | : __str_(__a), __hm_(nullptr), __mode_(__wch) { |
| 387 | __init_buf_ptrs(); |
| 388 | } |
| 389 | |
| 390 | _LIBCPP_HIDE_FROM_ABI explicit basic_stringbuf(string_type&& __s, |
| 391 | ios_base::openmode __wch = ios_base::in | ios_base::out) |
| 392 | : __str_(std::move(__s)), __hm_(nullptr), __mode_(__wch) { |
| 393 | __init_buf_ptrs(); |
| 394 | } |
| 395 | |
| 396 | template <class _SAlloc> |
| 397 | _LIBCPP_HIDE_FROM_ABI |
| 398 | basic_stringbuf(const basic_string<char_type, traits_type, _SAlloc>& __s, const allocator_type& __a) |
| 399 | : basic_stringbuf(__s, ios_base::in | ios_base::out, __a) {} |
| 400 | |
| 401 | template <class _SAlloc> |
| 402 | _LIBCPP_HIDE_FROM_ABI basic_stringbuf( |
| 403 | const basic_string<char_type, traits_type, _SAlloc>& __s, ios_base::openmode __wch, const allocator_type& __a) |
| 404 | : __str_(__s, __a), __hm_(nullptr), __mode_(__wch) { |
| 405 | __init_buf_ptrs(); |
| 406 | } |
| 407 | |
| 408 | template <class _SAlloc> |
| 409 | requires(!is_same_v<_SAlloc, allocator_type>) |
| 410 | _LIBCPP_HIDE_FROM_ABI explicit basic_stringbuf(const basic_string<char_type, traits_type, _SAlloc>& __s, |
| 411 | ios_base::openmode __wch = ios_base::in | ios_base::out) |
| 412 | : __str_(__s), __hm_(nullptr), __mode_(__wch) { |
| 413 | __init_buf_ptrs(); |
| 414 | } |
| 415 | # endif // _LIBCPP_STD_VER >= 20 |
| 416 | |
| 417 | # if _LIBCPP_STD_VER >= 26 |
| 418 | |
| 419 | template <class _Tp> |
| 420 | requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>> |
| 421 | _LIBCPP_HIDE_FROM_ABI explicit basic_stringbuf(const _Tp& __t, |
| 422 | ios_base::openmode __which = ios_base::in | ios_base::out) |
| 423 | : basic_stringbuf(__t, __which, _Allocator()) {} |
| 424 | |
| 425 | template <class _Tp> |
| 426 | requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>> |
| 427 | _LIBCPP_HIDE_FROM_ABI basic_stringbuf(const _Tp& __t, const _Allocator& __a) |
| 428 | : basic_stringbuf(__t, ios_base::in | ios_base::out, __a) {} |
| 429 | |
| 430 | template <class _Tp> |
| 431 | requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>> |
| 432 | _LIBCPP_HIDE_FROM_ABI basic_stringbuf(const _Tp& __t, ios_base::openmode __which, const _Allocator& __a) |
| 433 | : __hm_(nullptr), __mode_(__which) { |
| 434 | basic_string_view<_CharT, _Traits> __sv = __t; |
| 435 | __str_ = string_type(__sv, __a); |
| 436 | __init_buf_ptrs(); |
| 437 | } |
| 438 | |
| 439 | # endif // _LIBCPP_STD_VER >= 26 |
| 440 | |
| 441 | basic_stringbuf(const basic_stringbuf&) = delete; |
| 442 | basic_stringbuf(basic_stringbuf&& __rhs) : __mode_(__rhs.__mode_) { __move_init(rhs: std::move(__rhs)); } |
| 443 | |
| 444 | # if _LIBCPP_STD_VER >= 20 |
| 445 | _LIBCPP_HIDE_FROM_ABI basic_stringbuf(basic_stringbuf&& __rhs, const allocator_type& __a) |
| 446 | : basic_stringbuf(__rhs.__mode_, __a) { |
| 447 | __move_init(rhs: std::move(__rhs)); |
| 448 | } |
| 449 | # endif |
| 450 | |
| 451 | // [stringbuf.assign] Assign and swap: |
| 452 | basic_stringbuf& operator=(const basic_stringbuf&) = delete; |
| 453 | basic_stringbuf& operator=(basic_stringbuf&& __rhs); |
| 454 | void swap(basic_stringbuf& __rhs) |
| 455 | # if _LIBCPP_STD_VER >= 20 |
| 456 | noexcept(allocator_traits<allocator_type>::propagate_on_container_swap::value || |
| 457 | allocator_traits<allocator_type>::is_always_equal::value) |
| 458 | # endif |
| 459 | ; |
| 460 | |
| 461 | // [stringbuf.members] Member functions: |
| 462 | |
| 463 | # if _LIBCPP_STD_VER >= 20 |
| 464 | _LIBCPP_HIDE_FROM_ABI allocator_type get_allocator() const noexcept { return __str_.get_allocator(); } |
| 465 | # endif |
| 466 | |
| 467 | # if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_BUILDING_LIBRARY) |
| 468 | string_type str() const; |
| 469 | # else |
| 470 | _LIBCPP_HIDE_FROM_ABI string_type str() const& { return str(__str_.get_allocator()); } |
| 471 | |
| 472 | _LIBCPP_HIDE_FROM_ABI string_type str() && { |
| 473 | const basic_string_view<_CharT, _Traits> __view = view(); |
| 474 | typename string_type::size_type __pos = __view.empty() ? 0 : __view.data() - __str_.data(); |
| 475 | // In C++23, this is just string_type(std::move(__str_), __pos, __view.size(), __str_.get_allocator()); |
| 476 | // But we need something that works in C++20 also. |
| 477 | string_type __result(std::move(__str_), __str_.get_allocator()); |
| 478 | __result.resize(__pos + __view.size()); |
| 479 | __result.erase(0, __pos); |
| 480 | __init_buf_ptrs(); |
| 481 | return __result; |
| 482 | } |
| 483 | # endif // _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_BUILDING_LIBRARY) |
| 484 | |
| 485 | # if _LIBCPP_STD_VER >= 20 |
| 486 | template <class _SAlloc> |
| 487 | requires __is_allocator<_SAlloc>::value |
| 488 | _LIBCPP_HIDE_FROM_ABI basic_string<char_type, traits_type, _SAlloc> str(const _SAlloc& __sa) const { |
| 489 | return basic_string<_CharT, _Traits, _SAlloc>(view(), __sa); |
| 490 | } |
| 491 | |
| 492 | _LIBCPP_HIDE_FROM_ABI basic_string_view<char_type, traits_type> view() const noexcept; |
| 493 | # endif // _LIBCPP_STD_VER >= 20 |
| 494 | |
| 495 | void str(const string_type& __s) { |
| 496 | __str_ = __s; |
| 497 | __init_buf_ptrs(); |
| 498 | } |
| 499 | |
| 500 | # if _LIBCPP_STD_VER >= 20 |
| 501 | template <class _SAlloc> |
| 502 | requires(!is_same_v<_SAlloc, allocator_type>) |
| 503 | _LIBCPP_HIDE_FROM_ABI void str(const basic_string<char_type, traits_type, _SAlloc>& __s) { |
| 504 | __str_ = __s; |
| 505 | __init_buf_ptrs(); |
| 506 | } |
| 507 | |
| 508 | _LIBCPP_HIDE_FROM_ABI void str(string_type&& __s) { |
| 509 | __str_ = std::move(__s); |
| 510 | __init_buf_ptrs(); |
| 511 | } |
| 512 | # endif // _LIBCPP_STD_VER >= 20 |
| 513 | |
| 514 | # if _LIBCPP_STD_VER >= 26 |
| 515 | |
| 516 | template <class _Tp> |
| 517 | requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>> |
| 518 | _LIBCPP_HIDE_FROM_ABI void str(const _Tp& __t) { |
| 519 | basic_string_view<_CharT, _Traits> __sv = __t; |
| 520 | __str_ = __sv; |
| 521 | __init_buf_ptrs(); |
| 522 | } |
| 523 | |
| 524 | # endif // _LIBCPP_STD_VER >= 26 |
| 525 | |
| 526 | protected: |
| 527 | // [stringbuf.virtuals] Overridden virtual functions: |
| 528 | int_type underflow() override; |
| 529 | int_type pbackfail(int_type __c = traits_type::eof()) override; |
| 530 | int_type overflow(int_type __c = traits_type::eof()) override; |
| 531 | pos_type |
| 532 | seekoff(off_type __off, ios_base::seekdir __way, ios_base::openmode __wch = ios_base::in | ios_base::out) override; |
| 533 | _LIBCPP_HIDE_FROM_ABI_VIRTUAL |
| 534 | pos_type seekpos(pos_type __sp, ios_base::openmode __wch = ios_base::in | ios_base::out) override { |
| 535 | return seekoff(off: __sp, way: ios_base::beg, __wch); |
| 536 | } |
| 537 | }; |
| 538 | |
| 539 | template <class _CharT, class _Traits, class _Allocator> |
| 540 | _LIBCPP_HIDE_FROM_ABI void basic_stringbuf<_CharT, _Traits, _Allocator>::__move_init(basic_stringbuf&& __rhs) { |
| 541 | char_type* __p = const_cast<char_type*>(__rhs.__str_.data()); |
| 542 | ptrdiff_t __binp = -1; |
| 543 | ptrdiff_t __ninp = -1; |
| 544 | ptrdiff_t __einp = -1; |
| 545 | if (__rhs.eback() != nullptr) { |
| 546 | __binp = __rhs.eback() - __p; |
| 547 | __ninp = __rhs.gptr() - __p; |
| 548 | __einp = __rhs.egptr() - __p; |
| 549 | } |
| 550 | ptrdiff_t __bout = -1; |
| 551 | ptrdiff_t __nout = -1; |
| 552 | ptrdiff_t __eout = -1; |
| 553 | if (__rhs.pbase() != nullptr) { |
| 554 | __bout = __rhs.pbase() - __p; |
| 555 | __nout = __rhs.pptr() - __p; |
| 556 | __eout = __rhs.epptr() - __p; |
| 557 | } |
| 558 | ptrdiff_t __hm = __rhs.__hm_ == nullptr ? -1 : __rhs.__hm_ - __p; |
| 559 | __str_ = std::move(__rhs.__str_); |
| 560 | __p = const_cast<char_type*>(__str_.data()); |
| 561 | if (__binp != -1) |
| 562 | this->setg(__p + __binp, __p + __ninp, __p + __einp); |
| 563 | if (__bout != -1) { |
| 564 | this->setp(__p + __bout, __p + __eout); |
| 565 | this->__pbump(__nout); |
| 566 | } |
| 567 | __hm_ = __hm == -1 ? nullptr : __p + __hm; |
| 568 | __p = const_cast<char_type*>(__rhs.__str_.data()); |
| 569 | __rhs.setg(__p, __p, __p); |
| 570 | __rhs.setp(__p, __p); |
| 571 | __rhs.__hm_ = __p; |
| 572 | this->pubimbue(__rhs.getloc()); |
| 573 | } |
| 574 | |
| 575 | template <class _CharT, class _Traits, class _Allocator> |
| 576 | basic_stringbuf<_CharT, _Traits, _Allocator>& |
| 577 | basic_stringbuf<_CharT, _Traits, _Allocator>::operator=(basic_stringbuf&& __rhs) { |
| 578 | char_type* __p = const_cast<char_type*>(__rhs.__str_.data()); |
| 579 | ptrdiff_t __binp = -1; |
| 580 | ptrdiff_t __ninp = -1; |
| 581 | ptrdiff_t __einp = -1; |
| 582 | if (__rhs.eback() != nullptr) { |
| 583 | __binp = __rhs.eback() - __p; |
| 584 | __ninp = __rhs.gptr() - __p; |
| 585 | __einp = __rhs.egptr() - __p; |
| 586 | } |
| 587 | ptrdiff_t __bout = -1; |
| 588 | ptrdiff_t __nout = -1; |
| 589 | ptrdiff_t __eout = -1; |
| 590 | if (__rhs.pbase() != nullptr) { |
| 591 | __bout = __rhs.pbase() - __p; |
| 592 | __nout = __rhs.pptr() - __p; |
| 593 | __eout = __rhs.epptr() - __p; |
| 594 | } |
| 595 | ptrdiff_t __hm = __rhs.__hm_ == nullptr ? -1 : __rhs.__hm_ - __p; |
| 596 | __str_ = std::move(__rhs.__str_); |
| 597 | __p = const_cast<char_type*>(__str_.data()); |
| 598 | if (__binp != -1) |
| 599 | this->setg(__p + __binp, __p + __ninp, __p + __einp); |
| 600 | else |
| 601 | this->setg(nullptr, nullptr, nullptr); |
| 602 | if (__bout != -1) { |
| 603 | this->setp(__p + __bout, __p + __eout); |
| 604 | this->__pbump(__nout); |
| 605 | } else |
| 606 | this->setp(nullptr, nullptr); |
| 607 | |
| 608 | __hm_ = __hm == -1 ? nullptr : __p + __hm; |
| 609 | __mode_ = __rhs.__mode_; |
| 610 | __p = const_cast<char_type*>(__rhs.__str_.data()); |
| 611 | __rhs.setg(__p, __p, __p); |
| 612 | __rhs.setp(__p, __p); |
| 613 | __rhs.__hm_ = __p; |
| 614 | this->pubimbue(__rhs.getloc()); |
| 615 | return *this; |
| 616 | } |
| 617 | |
| 618 | template <class _CharT, class _Traits, class _Allocator> |
| 619 | void basic_stringbuf<_CharT, _Traits, _Allocator>::swap(basic_stringbuf& __rhs) |
| 620 | # if _LIBCPP_STD_VER >= 20 |
| 621 | noexcept(allocator_traits<_Allocator>::propagate_on_container_swap::value || |
| 622 | allocator_traits<_Allocator>::is_always_equal::value) |
| 623 | # endif |
| 624 | { |
| 625 | char_type* __p = const_cast<char_type*>(__rhs.__str_.data()); |
| 626 | ptrdiff_t __rbinp = -1; |
| 627 | ptrdiff_t __rninp = -1; |
| 628 | ptrdiff_t __reinp = -1; |
| 629 | if (__rhs.eback() != nullptr) { |
| 630 | __rbinp = __rhs.eback() - __p; |
| 631 | __rninp = __rhs.gptr() - __p; |
| 632 | __reinp = __rhs.egptr() - __p; |
| 633 | } |
| 634 | ptrdiff_t __rbout = -1; |
| 635 | ptrdiff_t __rnout = -1; |
| 636 | ptrdiff_t __reout = -1; |
| 637 | if (__rhs.pbase() != nullptr) { |
| 638 | __rbout = __rhs.pbase() - __p; |
| 639 | __rnout = __rhs.pptr() - __p; |
| 640 | __reout = __rhs.epptr() - __p; |
| 641 | } |
| 642 | ptrdiff_t __rhm = __rhs.__hm_ == nullptr ? -1 : __rhs.__hm_ - __p; |
| 643 | __p = const_cast<char_type*>(__str_.data()); |
| 644 | ptrdiff_t __lbinp = -1; |
| 645 | ptrdiff_t __lninp = -1; |
| 646 | ptrdiff_t __leinp = -1; |
| 647 | if (this->eback() != nullptr) { |
| 648 | __lbinp = this->eback() - __p; |
| 649 | __lninp = this->gptr() - __p; |
| 650 | __leinp = this->egptr() - __p; |
| 651 | } |
| 652 | ptrdiff_t __lbout = -1; |
| 653 | ptrdiff_t __lnout = -1; |
| 654 | ptrdiff_t __leout = -1; |
| 655 | if (this->pbase() != nullptr) { |
| 656 | __lbout = this->pbase() - __p; |
| 657 | __lnout = this->pptr() - __p; |
| 658 | __leout = this->epptr() - __p; |
| 659 | } |
| 660 | ptrdiff_t __lhm = __hm_ == nullptr ? -1 : __hm_ - __p; |
| 661 | std::swap(__mode_, __rhs.__mode_); |
| 662 | __str_.swap(__rhs.__str_); |
| 663 | __p = const_cast<char_type*>(__str_.data()); |
| 664 | if (__rbinp != -1) |
| 665 | this->setg(__p + __rbinp, __p + __rninp, __p + __reinp); |
| 666 | else |
| 667 | this->setg(nullptr, nullptr, nullptr); |
| 668 | if (__rbout != -1) { |
| 669 | this->setp(__p + __rbout, __p + __reout); |
| 670 | this->__pbump(__rnout); |
| 671 | } else |
| 672 | this->setp(nullptr, nullptr); |
| 673 | __hm_ = __rhm == -1 ? nullptr : __p + __rhm; |
| 674 | __p = const_cast<char_type*>(__rhs.__str_.data()); |
| 675 | if (__lbinp != -1) |
| 676 | __rhs.setg(__p + __lbinp, __p + __lninp, __p + __leinp); |
| 677 | else |
| 678 | __rhs.setg(nullptr, nullptr, nullptr); |
| 679 | if (__lbout != -1) { |
| 680 | __rhs.setp(__p + __lbout, __p + __leout); |
| 681 | __rhs.__pbump(__lnout); |
| 682 | } else |
| 683 | __rhs.setp(nullptr, nullptr); |
| 684 | __rhs.__hm_ = __lhm == -1 ? nullptr : __p + __lhm; |
| 685 | locale __tl = __rhs.getloc(); |
| 686 | __rhs.pubimbue(this->getloc()); |
| 687 | this->pubimbue(__tl); |
| 688 | } |
| 689 | |
| 690 | template <class _CharT, class _Traits, class _Allocator> |
| 691 | inline _LIBCPP_HIDE_FROM_ABI void |
| 692 | swap(basic_stringbuf<_CharT, _Traits, _Allocator>& __x, basic_stringbuf<_CharT, _Traits, _Allocator>& __y) |
| 693 | # if _LIBCPP_STD_VER >= 20 |
| 694 | noexcept(noexcept(__x.swap(__y))) |
| 695 | # endif |
| 696 | { |
| 697 | __x.swap(__y); |
| 698 | } |
| 699 | |
| 700 | # if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_BUILDING_LIBRARY) |
| 701 | template <class _CharT, class _Traits, class _Allocator> |
| 702 | basic_string<_CharT, _Traits, _Allocator> basic_stringbuf<_CharT, _Traits, _Allocator>::str() const { |
| 703 | if (__mode_ & ios_base::out) { |
| 704 | if (__hm_ < this->pptr()) |
| 705 | __hm_ = this->pptr(); |
| 706 | return string_type(this->pbase(), __hm_, __str_.get_allocator()); |
| 707 | } else if (__mode_ & ios_base::in) |
| 708 | return string_type(this->eback(), this->egptr(), __str_.get_allocator()); |
| 709 | return string_type(__str_.get_allocator()); |
| 710 | } |
| 711 | # endif // _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_BUILDING_LIBRARY) |
| 712 | |
| 713 | template <class _CharT, class _Traits, class _Allocator> |
| 714 | _LIBCPP_HIDE_FROM_ABI void basic_stringbuf<_CharT, _Traits, _Allocator>::__init_buf_ptrs() { |
| 715 | __hm_ = nullptr; |
| 716 | char_type* __data = const_cast<char_type*>(__str_.data()); |
| 717 | typename string_type::size_type __sz = __str_.size(); |
| 718 | if (__mode_ & ios_base::in) { |
| 719 | __hm_ = __data + __sz; |
| 720 | this->setg(__data, __data, __hm_); |
| 721 | } |
| 722 | if (__mode_ & ios_base::out) { |
| 723 | __hm_ = __data + __sz; |
| 724 | __str_.resize(__str_.capacity()); |
| 725 | this->setp(__data, __data + __str_.size()); |
| 726 | if (__mode_ & (ios_base::app | ios_base::ate)) { |
| 727 | while (__sz > INT_MAX) { |
| 728 | this->pbump(INT_MAX); |
| 729 | __sz -= INT_MAX; |
| 730 | } |
| 731 | if (__sz > 0) |
| 732 | this->pbump(__sz); |
| 733 | } |
| 734 | } |
| 735 | } |
| 736 | |
| 737 | # if _LIBCPP_STD_VER >= 20 |
| 738 | template <class _CharT, class _Traits, class _Allocator> |
| 739 | _LIBCPP_HIDE_FROM_ABI basic_string_view<_CharT, _Traits> |
| 740 | basic_stringbuf<_CharT, _Traits, _Allocator>::view() const noexcept { |
| 741 | if (__mode_ & ios_base::out) { |
| 742 | if (__hm_ < this->pptr()) |
| 743 | __hm_ = this->pptr(); |
| 744 | return basic_string_view<_CharT, _Traits>(this->pbase(), __hm_); |
| 745 | } else if (__mode_ & ios_base::in) |
| 746 | return basic_string_view<_CharT, _Traits>(this->eback(), this->egptr()); |
| 747 | return basic_string_view<_CharT, _Traits>(); |
| 748 | } |
| 749 | # endif // _LIBCPP_STD_VER >= 20 |
| 750 | |
| 751 | template <class _CharT, class _Traits, class _Allocator> |
| 752 | typename basic_stringbuf<_CharT, _Traits, _Allocator>::int_type |
| 753 | basic_stringbuf<_CharT, _Traits, _Allocator>::underflow() { |
| 754 | if (__hm_ < this->pptr()) |
| 755 | __hm_ = this->pptr(); |
| 756 | if (__mode_ & ios_base::in) { |
| 757 | if (this->egptr() < __hm_) |
| 758 | this->setg(this->eback(), this->gptr(), __hm_); |
| 759 | if (this->gptr() < this->egptr()) |
| 760 | return traits_type::to_int_type(*this->gptr()); |
| 761 | } |
| 762 | return traits_type::eof(); |
| 763 | } |
| 764 | |
| 765 | template <class _CharT, class _Traits, class _Allocator> |
| 766 | typename basic_stringbuf<_CharT, _Traits, _Allocator>::int_type |
| 767 | basic_stringbuf<_CharT, _Traits, _Allocator>::pbackfail(int_type __c) { |
| 768 | if (__hm_ < this->pptr()) |
| 769 | __hm_ = this->pptr(); |
| 770 | if (this->eback() < this->gptr()) { |
| 771 | if (traits_type::eq_int_type(__c, traits_type::eof())) { |
| 772 | this->setg(this->eback(), this->gptr() - 1, __hm_); |
| 773 | return traits_type::not_eof(__c); |
| 774 | } |
| 775 | if ((__mode_ & ios_base::out) || traits_type::eq(traits_type::to_char_type(__c), this->gptr()[-1])) { |
| 776 | this->setg(this->eback(), this->gptr() - 1, __hm_); |
| 777 | *this->gptr() = traits_type::to_char_type(__c); |
| 778 | return __c; |
| 779 | } |
| 780 | } |
| 781 | return traits_type::eof(); |
| 782 | } |
| 783 | |
| 784 | template <class _CharT, class _Traits, class _Allocator> |
| 785 | typename basic_stringbuf<_CharT, _Traits, _Allocator>::int_type |
| 786 | basic_stringbuf<_CharT, _Traits, _Allocator>::overflow(int_type __c) { |
| 787 | if (!traits_type::eq_int_type(__c, traits_type::eof())) { |
| 788 | ptrdiff_t __ninp = this->gptr() - this->eback(); |
| 789 | if (this->pptr() == this->epptr()) { |
| 790 | if (!(__mode_ & ios_base::out)) |
| 791 | return traits_type::eof(); |
| 792 | # if _LIBCPP_HAS_EXCEPTIONS |
| 793 | try { |
| 794 | # endif // _LIBCPP_HAS_EXCEPTIONS |
| 795 | ptrdiff_t __nout = this->pptr() - this->pbase(); |
| 796 | ptrdiff_t __hm = __hm_ - this->pbase(); |
| 797 | __str_.push_back(char_type()); |
| 798 | __str_.resize(__str_.capacity()); |
| 799 | char_type* __p = const_cast<char_type*>(__str_.data()); |
| 800 | this->setp(__p, __p + __str_.size()); |
| 801 | this->__pbump(__nout); |
| 802 | __hm_ = this->pbase() + __hm; |
| 803 | # if _LIBCPP_HAS_EXCEPTIONS |
| 804 | } catch (...) { |
| 805 | return traits_type::eof(); |
| 806 | } |
| 807 | # endif // _LIBCPP_HAS_EXCEPTIONS |
| 808 | } |
| 809 | __hm_ = std::max(this->pptr() + 1, __hm_); |
| 810 | if (__mode_ & ios_base::in) { |
| 811 | char_type* __p = const_cast<char_type*>(__str_.data()); |
| 812 | this->setg(__p, __p + __ninp, __hm_); |
| 813 | } |
| 814 | return this->sputc(traits_type::to_char_type(__c)); |
| 815 | } |
| 816 | return traits_type::not_eof(__c); |
| 817 | } |
| 818 | |
| 819 | template <class _CharT, class _Traits, class _Allocator> |
| 820 | typename basic_stringbuf<_CharT, _Traits, _Allocator>::pos_type basic_stringbuf<_CharT, _Traits, _Allocator>::seekoff( |
| 821 | off_type __off, ios_base::seekdir __way, ios_base::openmode __wch) { |
| 822 | if (__hm_ < this->pptr()) |
| 823 | __hm_ = this->pptr(); |
| 824 | if ((__wch & (ios_base::in | ios_base::out)) == 0) |
| 825 | return pos_type(-1); |
| 826 | if ((__wch & (ios_base::in | ios_base::out)) == (ios_base::in | ios_base::out) && __way == ios_base::cur) |
| 827 | return pos_type(-1); |
| 828 | const ptrdiff_t __hm = __hm_ == nullptr ? 0 : __hm_ - __str_.data(); |
| 829 | off_type __noff; |
| 830 | switch (__way) { |
| 831 | case ios_base::beg: |
| 832 | __noff = 0; |
| 833 | break; |
| 834 | case ios_base::cur: |
| 835 | if (__wch & ios_base::in) |
| 836 | __noff = this->gptr() - this->eback(); |
| 837 | else |
| 838 | __noff = this->pptr() - this->pbase(); |
| 839 | break; |
| 840 | case ios_base::end: |
| 841 | __noff = __hm; |
| 842 | break; |
| 843 | default: |
| 844 | return pos_type(-1); |
| 845 | } |
| 846 | __noff += __off; |
| 847 | if (__noff < 0 || __hm < __noff) |
| 848 | return pos_type(-1); |
| 849 | if (__noff != 0) { |
| 850 | if ((__wch & ios_base::in) && this->gptr() == nullptr) |
| 851 | return pos_type(-1); |
| 852 | if ((__wch & ios_base::out) && this->pptr() == nullptr) |
| 853 | return pos_type(-1); |
| 854 | } |
| 855 | if (__wch & ios_base::in) |
| 856 | this->setg(this->eback(), this->eback() + __noff, __hm_); |
| 857 | if (__wch & ios_base::out) { |
| 858 | this->setp(this->pbase(), this->epptr()); |
| 859 | this->__pbump(__noff); |
| 860 | } |
| 861 | return pos_type(__noff); |
| 862 | } |
| 863 | |
| 864 | // Class template basic_istringstream [istringstream] |
| 865 | |
| 866 | template <class _CharT, class _Traits, class _Allocator> |
| 867 | class basic_istringstream : public basic_istream<_CharT, _Traits> { |
| 868 | public: |
| 869 | typedef _CharT char_type; |
| 870 | typedef _Traits traits_type; |
| 871 | typedef typename traits_type::int_type int_type; |
| 872 | typedef typename traits_type::pos_type pos_type; |
| 873 | typedef typename traits_type::off_type off_type; |
| 874 | typedef _Allocator allocator_type; |
| 875 | |
| 876 | typedef basic_string<char_type, traits_type, allocator_type> string_type; |
| 877 | |
| 878 | private: |
| 879 | basic_stringbuf<char_type, traits_type, allocator_type> __sb_; |
| 880 | |
| 881 | public: |
| 882 | // [istringstream.cons] Constructors: |
| 883 | _LIBCPP_HIDE_FROM_ABI basic_istringstream() |
| 884 | : basic_istream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(ios_base::in) {} |
| 885 | |
| 886 | _LIBCPP_HIDE_FROM_ABI explicit basic_istringstream(ios_base::openmode __wch) |
| 887 | : basic_istream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__wch | ios_base::in) {} |
| 888 | |
| 889 | _LIBCPP_HIDE_FROM_ABI explicit basic_istringstream(const string_type& __s, ios_base::openmode __wch = ios_base::in) |
| 890 | : basic_istream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__s, __wch | ios_base::in) {} |
| 891 | |
| 892 | # if _LIBCPP_STD_VER >= 20 |
| 893 | _LIBCPP_HIDE_FROM_ABI basic_istringstream(ios_base::openmode __wch, const _Allocator& __a) |
| 894 | : basic_istream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__wch | ios_base::in, __a) {} |
| 895 | |
| 896 | _LIBCPP_HIDE_FROM_ABI explicit basic_istringstream(string_type&& __s, ios_base::openmode __wch = ios_base::in) |
| 897 | : basic_istream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(std::move(__s), __wch | ios_base::in) {} |
| 898 | |
| 899 | template <class _SAlloc> |
| 900 | _LIBCPP_HIDE_FROM_ABI basic_istringstream(const basic_string<_CharT, _Traits, _SAlloc>& __s, const _Allocator& __a) |
| 901 | : basic_istringstream(__s, ios_base::in, __a) {} |
| 902 | |
| 903 | template <class _SAlloc> |
| 904 | _LIBCPP_HIDE_FROM_ABI basic_istringstream( |
| 905 | const basic_string<_CharT, _Traits, _SAlloc>& __s, ios_base::openmode __wch, const _Allocator& __a) |
| 906 | : basic_istream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__s, __wch | ios_base::in, __a) {} |
| 907 | |
| 908 | template <class _SAlloc> |
| 909 | _LIBCPP_HIDE_FROM_ABI explicit basic_istringstream(const basic_string<_CharT, _Traits, _SAlloc>& __s, |
| 910 | ios_base::openmode __wch = ios_base::in) |
| 911 | : basic_istream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__s, __wch | ios_base::in) {} |
| 912 | # endif // _LIBCPP_STD_VER >= 20 |
| 913 | |
| 914 | # if _LIBCPP_STD_VER >= 26 |
| 915 | |
| 916 | template <class _Tp> |
| 917 | requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>> |
| 918 | _LIBCPP_HIDE_FROM_ABI explicit basic_istringstream(const _Tp& __t, ios_base::openmode __which = ios_base::in) |
| 919 | : basic_istringstream(__t, __which, _Allocator()) {} |
| 920 | |
| 921 | template <class _Tp> |
| 922 | requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>> |
| 923 | _LIBCPP_HIDE_FROM_ABI basic_istringstream(const _Tp& __t, const _Allocator& __a) |
| 924 | : basic_istringstream(__t, ios_base::in, __a) {} |
| 925 | |
| 926 | template <class _Tp> |
| 927 | requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>> |
| 928 | _LIBCPP_HIDE_FROM_ABI basic_istringstream(const _Tp& __t, ios_base::openmode __which, const _Allocator& __a) |
| 929 | : basic_istream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__t, __which | ios_base::in, __a) {} |
| 930 | |
| 931 | # endif // _LIBCPP_STD_VER >= 26 |
| 932 | |
| 933 | basic_istringstream(const basic_istringstream&) = delete; |
| 934 | _LIBCPP_HIDE_FROM_ABI basic_istringstream(basic_istringstream&& __rhs) |
| 935 | : basic_istream<_CharT, _Traits>(std::move(__rhs)), __sb_(std::move(__rhs.__sb_)) { |
| 936 | basic_istream<_CharT, _Traits>::set_rdbuf(std::addressof(__sb_)); |
| 937 | } |
| 938 | |
| 939 | // [istringstream.assign] Assign and swap: |
| 940 | basic_istringstream& operator=(const basic_istringstream&) = delete; |
| 941 | basic_istringstream& operator=(basic_istringstream&& __rhs) { |
| 942 | basic_istream<char_type, traits_type>::operator=(std::move(__rhs)); |
| 943 | __sb_ = std::move(__rhs.__sb_); |
| 944 | return *this; |
| 945 | } |
| 946 | _LIBCPP_HIDE_FROM_ABI void swap(basic_istringstream& __rhs) { |
| 947 | basic_istream<char_type, traits_type>::swap(__rhs); |
| 948 | __sb_.swap(__rhs.__sb_); |
| 949 | } |
| 950 | |
| 951 | // [istringstream.members] Member functions: |
| 952 | _LIBCPP_HIDE_FROM_ABI basic_stringbuf<char_type, traits_type, allocator_type>* rdbuf() const { |
| 953 | return const_cast<basic_stringbuf<char_type, traits_type, allocator_type>*>(std::addressof(__sb_)); |
| 954 | } |
| 955 | |
| 956 | # if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_BUILDING_LIBRARY) |
| 957 | _LIBCPP_HIDE_FROM_ABI string_type str() const { return __sb_.str(); } |
| 958 | # else |
| 959 | _LIBCPP_HIDE_FROM_ABI string_type str() const& { return __sb_.str(); } |
| 960 | |
| 961 | _LIBCPP_HIDE_FROM_ABI string_type str() && { return std::move(__sb_).str(); } |
| 962 | # endif |
| 963 | |
| 964 | # if _LIBCPP_STD_VER >= 20 |
| 965 | template <class _SAlloc> |
| 966 | requires __is_allocator<_SAlloc>::value |
| 967 | _LIBCPP_HIDE_FROM_ABI basic_string<char_type, traits_type, _SAlloc> str(const _SAlloc& __sa) const { |
| 968 | return __sb_.str(__sa); |
| 969 | } |
| 970 | |
| 971 | _LIBCPP_HIDE_FROM_ABI basic_string_view<char_type, traits_type> view() const noexcept { return __sb_.view(); } |
| 972 | # endif // _LIBCPP_STD_VER >= 20 |
| 973 | |
| 974 | _LIBCPP_HIDE_FROM_ABI void str(const string_type& __s) { __sb_.str(__s); } |
| 975 | |
| 976 | # if _LIBCPP_STD_VER >= 20 |
| 977 | template <class _SAlloc> |
| 978 | _LIBCPP_HIDE_FROM_ABI void str(const basic_string<char_type, traits_type, _SAlloc>& __s) { |
| 979 | __sb_.str(__s); |
| 980 | } |
| 981 | |
| 982 | _LIBCPP_HIDE_FROM_ABI void str(string_type&& __s) { __sb_.str(std::move(__s)); } |
| 983 | # endif // _LIBCPP_STD_VER >= 20 |
| 984 | |
| 985 | # if _LIBCPP_STD_VER >= 26 |
| 986 | template <class _Tp> |
| 987 | requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>> |
| 988 | _LIBCPP_HIDE_FROM_ABI void str(const _Tp& __t) { |
| 989 | rdbuf()->str(__t); |
| 990 | } |
| 991 | # endif // _LIBCPP_STD_VER >= 26 |
| 992 | }; |
| 993 | |
| 994 | template <class _CharT, class _Traits, class _Allocator> |
| 995 | inline _LIBCPP_HIDE_FROM_ABI void |
| 996 | swap(basic_istringstream<_CharT, _Traits, _Allocator>& __x, basic_istringstream<_CharT, _Traits, _Allocator>& __y) { |
| 997 | __x.swap(__y); |
| 998 | } |
| 999 | |
| 1000 | // Class template basic_ostringstream [ostringstream] |
| 1001 | |
| 1002 | template <class _CharT, class _Traits, class _Allocator> |
| 1003 | class basic_ostringstream : public basic_ostream<_CharT, _Traits> { |
| 1004 | public: |
| 1005 | typedef _CharT char_type; |
| 1006 | typedef _Traits traits_type; |
| 1007 | typedef typename traits_type::int_type int_type; |
| 1008 | typedef typename traits_type::pos_type pos_type; |
| 1009 | typedef typename traits_type::off_type off_type; |
| 1010 | typedef _Allocator allocator_type; |
| 1011 | |
| 1012 | typedef basic_string<char_type, traits_type, allocator_type> string_type; |
| 1013 | |
| 1014 | private: |
| 1015 | basic_stringbuf<char_type, traits_type, allocator_type> __sb_; |
| 1016 | |
| 1017 | public: |
| 1018 | // [ostringstream.cons] Constructors: |
| 1019 | _LIBCPP_HIDE_FROM_ABI basic_ostringstream() |
| 1020 | : basic_ostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(ios_base::out) {} |
| 1021 | |
| 1022 | _LIBCPP_HIDE_FROM_ABI explicit basic_ostringstream(ios_base::openmode __wch) |
| 1023 | : basic_ostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__wch | ios_base::out) {} |
| 1024 | |
| 1025 | _LIBCPP_HIDE_FROM_ABI explicit basic_ostringstream(const string_type& __s, ios_base::openmode __wch = ios_base::out) |
| 1026 | : basic_ostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__s, __wch | ios_base::out) {} |
| 1027 | |
| 1028 | # if _LIBCPP_STD_VER >= 20 |
| 1029 | _LIBCPP_HIDE_FROM_ABI basic_ostringstream(ios_base::openmode __wch, const _Allocator& __a) |
| 1030 | : basic_ostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__wch | ios_base::out, __a) {} |
| 1031 | |
| 1032 | _LIBCPP_HIDE_FROM_ABI explicit basic_ostringstream(string_type&& __s, ios_base::openmode __wch = ios_base::out) |
| 1033 | : basic_ostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(std::move(__s), __wch | ios_base::out) {} |
| 1034 | |
| 1035 | template <class _SAlloc> |
| 1036 | _LIBCPP_HIDE_FROM_ABI basic_ostringstream(const basic_string<_CharT, _Traits, _SAlloc>& __s, const _Allocator& __a) |
| 1037 | : basic_ostringstream(__s, ios_base::out, __a) {} |
| 1038 | |
| 1039 | template <class _SAlloc> |
| 1040 | _LIBCPP_HIDE_FROM_ABI basic_ostringstream( |
| 1041 | const basic_string<_CharT, _Traits, _SAlloc>& __s, ios_base::openmode __wch, const _Allocator& __a) |
| 1042 | : basic_ostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__s, __wch | ios_base::out, __a) {} |
| 1043 | |
| 1044 | template <class _SAlloc> |
| 1045 | requires(!is_same_v<_SAlloc, allocator_type>) |
| 1046 | _LIBCPP_HIDE_FROM_ABI explicit basic_ostringstream(const basic_string<_CharT, _Traits, _SAlloc>& __s, |
| 1047 | ios_base::openmode __wch = ios_base::out) |
| 1048 | : basic_ostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__s, __wch | ios_base::out) {} |
| 1049 | # endif // _LIBCPP_STD_VER >= 20 |
| 1050 | |
| 1051 | # if _LIBCPP_STD_VER >= 26 |
| 1052 | |
| 1053 | template <class _Tp> |
| 1054 | requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>> |
| 1055 | _LIBCPP_HIDE_FROM_ABI explicit basic_ostringstream(const _Tp& __t, ios_base::openmode __which = ios_base::out) |
| 1056 | : basic_ostringstream(__t, __which | ios_base::out, _Allocator()) {} |
| 1057 | |
| 1058 | template <class _Tp> |
| 1059 | requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>> |
| 1060 | _LIBCPP_HIDE_FROM_ABI basic_ostringstream(const _Tp& __t, const _Allocator& __a) |
| 1061 | : basic_ostringstream(__t, ios_base::out, __a) {} |
| 1062 | |
| 1063 | template <class _Tp> |
| 1064 | requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>> |
| 1065 | _LIBCPP_HIDE_FROM_ABI basic_ostringstream(const _Tp& __t, ios_base::openmode __which, const _Allocator& __a) |
| 1066 | : basic_ostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__t, __which | ios_base::out, __a) {} |
| 1067 | |
| 1068 | # endif // _LIBCPP_STD_VER >= 26 |
| 1069 | |
| 1070 | basic_ostringstream(const basic_ostringstream&) = delete; |
| 1071 | _LIBCPP_HIDE_FROM_ABI basic_ostringstream(basic_ostringstream&& __rhs) |
| 1072 | : basic_ostream<_CharT, _Traits>(std::move(__rhs)), __sb_(std::move(__rhs.__sb_)) { |
| 1073 | basic_ostream<_CharT, _Traits>::set_rdbuf(std::addressof(__sb_)); |
| 1074 | } |
| 1075 | |
| 1076 | // [ostringstream.assign] Assign and swap: |
| 1077 | basic_ostringstream& operator=(const basic_ostringstream&) = delete; |
| 1078 | basic_ostringstream& operator=(basic_ostringstream&& __rhs) { |
| 1079 | basic_ostream<char_type, traits_type>::operator=(std::move(__rhs)); |
| 1080 | __sb_ = std::move(__rhs.__sb_); |
| 1081 | return *this; |
| 1082 | } |
| 1083 | |
| 1084 | _LIBCPP_HIDE_FROM_ABI void swap(basic_ostringstream& __rhs) { |
| 1085 | basic_ostream<char_type, traits_type>::swap(__rhs); |
| 1086 | __sb_.swap(__rhs.__sb_); |
| 1087 | } |
| 1088 | |
| 1089 | // [ostringstream.members] Member functions: |
| 1090 | _LIBCPP_HIDE_FROM_ABI basic_stringbuf<char_type, traits_type, allocator_type>* rdbuf() const { |
| 1091 | return const_cast<basic_stringbuf<char_type, traits_type, allocator_type>*>(std::addressof(__sb_)); |
| 1092 | } |
| 1093 | |
| 1094 | # if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_BUILDING_LIBRARY) |
| 1095 | _LIBCPP_HIDE_FROM_ABI string_type str() const { return __sb_.str(); } |
| 1096 | # else |
| 1097 | _LIBCPP_HIDE_FROM_ABI string_type str() const& { return __sb_.str(); } |
| 1098 | |
| 1099 | _LIBCPP_HIDE_FROM_ABI string_type str() && { return std::move(__sb_).str(); } |
| 1100 | # endif |
| 1101 | |
| 1102 | # if _LIBCPP_STD_VER >= 20 |
| 1103 | template <class _SAlloc> |
| 1104 | requires __is_allocator<_SAlloc>::value |
| 1105 | _LIBCPP_HIDE_FROM_ABI basic_string<char_type, traits_type, _SAlloc> str(const _SAlloc& __sa) const { |
| 1106 | return __sb_.str(__sa); |
| 1107 | } |
| 1108 | |
| 1109 | _LIBCPP_HIDE_FROM_ABI basic_string_view<char_type, traits_type> view() const noexcept { return __sb_.view(); } |
| 1110 | # endif // _LIBCPP_STD_VER >= 20 |
| 1111 | |
| 1112 | _LIBCPP_HIDE_FROM_ABI void str(const string_type& __s) { __sb_.str(__s); } |
| 1113 | |
| 1114 | # if _LIBCPP_STD_VER >= 20 |
| 1115 | template <class _SAlloc> |
| 1116 | _LIBCPP_HIDE_FROM_ABI void str(const basic_string<char_type, traits_type, _SAlloc>& __s) { |
| 1117 | __sb_.str(__s); |
| 1118 | } |
| 1119 | |
| 1120 | _LIBCPP_HIDE_FROM_ABI void str(string_type&& __s) { __sb_.str(std::move(__s)); } |
| 1121 | # endif // _LIBCPP_STD_VER >= 20 |
| 1122 | |
| 1123 | # if _LIBCPP_STD_VER >= 26 |
| 1124 | template <class _Tp> |
| 1125 | requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>> |
| 1126 | _LIBCPP_HIDE_FROM_ABI void str(const _Tp& __t) { |
| 1127 | rdbuf()->str(__t); |
| 1128 | } |
| 1129 | # endif // _LIBCPP_STD_VER >= 26 |
| 1130 | }; |
| 1131 | |
| 1132 | template <class _CharT, class _Traits, class _Allocator> |
| 1133 | inline _LIBCPP_HIDE_FROM_ABI void |
| 1134 | swap(basic_ostringstream<_CharT, _Traits, _Allocator>& __x, basic_ostringstream<_CharT, _Traits, _Allocator>& __y) { |
| 1135 | __x.swap(__y); |
| 1136 | } |
| 1137 | |
| 1138 | // Class template basic_stringstream [stringstream] |
| 1139 | |
| 1140 | template <class _CharT, class _Traits, class _Allocator> |
| 1141 | class basic_stringstream : public basic_iostream<_CharT, _Traits> { |
| 1142 | public: |
| 1143 | typedef _CharT char_type; |
| 1144 | typedef _Traits traits_type; |
| 1145 | typedef typename traits_type::int_type int_type; |
| 1146 | typedef typename traits_type::pos_type pos_type; |
| 1147 | typedef typename traits_type::off_type off_type; |
| 1148 | typedef _Allocator allocator_type; |
| 1149 | |
| 1150 | typedef basic_string<char_type, traits_type, allocator_type> string_type; |
| 1151 | |
| 1152 | private: |
| 1153 | basic_stringbuf<char_type, traits_type, allocator_type> __sb_; |
| 1154 | |
| 1155 | public: |
| 1156 | // [stringstream.cons] constructors |
| 1157 | _LIBCPP_HIDE_FROM_ABI basic_stringstream() |
| 1158 | : basic_iostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(ios_base::in | ios_base::out) {} |
| 1159 | |
| 1160 | _LIBCPP_HIDE_FROM_ABI explicit basic_stringstream(ios_base::openmode __wch) |
| 1161 | : basic_iostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__wch) {} |
| 1162 | |
| 1163 | _LIBCPP_HIDE_FROM_ABI explicit basic_stringstream(const string_type& __s, |
| 1164 | ios_base::openmode __wch = ios_base::in | ios_base::out) |
| 1165 | : basic_iostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__s, __wch) {} |
| 1166 | |
| 1167 | # if _LIBCPP_STD_VER >= 20 |
| 1168 | _LIBCPP_HIDE_FROM_ABI basic_stringstream(ios_base::openmode __wch, const _Allocator& __a) |
| 1169 | : basic_iostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__wch, __a) {} |
| 1170 | |
| 1171 | _LIBCPP_HIDE_FROM_ABI explicit basic_stringstream(string_type&& __s, |
| 1172 | ios_base::openmode __wch = ios_base::out | ios_base::in) |
| 1173 | : basic_iostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(std::move(__s), __wch) {} |
| 1174 | |
| 1175 | template <class _SAlloc> |
| 1176 | _LIBCPP_HIDE_FROM_ABI basic_stringstream(const basic_string<_CharT, _Traits, _SAlloc>& __s, const _Allocator& __a) |
| 1177 | : basic_stringstream(__s, ios_base::out | ios_base::in, __a) {} |
| 1178 | |
| 1179 | template <class _SAlloc> |
| 1180 | _LIBCPP_HIDE_FROM_ABI |
| 1181 | basic_stringstream(const basic_string<_CharT, _Traits, _SAlloc>& __s, ios_base::openmode __wch, const _Allocator& __a) |
| 1182 | : basic_iostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__s, __wch, __a) {} |
| 1183 | |
| 1184 | template <class _SAlloc> |
| 1185 | requires(!is_same_v<_SAlloc, allocator_type>) |
| 1186 | _LIBCPP_HIDE_FROM_ABI explicit basic_stringstream(const basic_string<_CharT, _Traits, _SAlloc>& __s, |
| 1187 | ios_base::openmode __wch = ios_base::out | ios_base::in) |
| 1188 | : basic_iostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__s, __wch) {} |
| 1189 | # endif // _LIBCPP_STD_VER >= 20 |
| 1190 | |
| 1191 | # if _LIBCPP_STD_VER >= 26 |
| 1192 | |
| 1193 | template <class _Tp> |
| 1194 | requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>> |
| 1195 | _LIBCPP_HIDE_FROM_ABI explicit basic_stringstream(const _Tp& __t, |
| 1196 | ios_base::openmode __which = ios_base::out | ios_base::in) |
| 1197 | : basic_stringstream(__t, __which, _Allocator()) {} |
| 1198 | |
| 1199 | template <class _Tp> |
| 1200 | requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>> |
| 1201 | _LIBCPP_HIDE_FROM_ABI basic_stringstream(const _Tp& __t, const _Allocator& __a) |
| 1202 | : basic_stringstream(__t, ios_base::out | ios_base::in, __a) {} |
| 1203 | |
| 1204 | template <class _Tp> |
| 1205 | requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>> |
| 1206 | _LIBCPP_HIDE_FROM_ABI basic_stringstream(const _Tp& __t, ios_base::openmode __which, const _Allocator& __a) |
| 1207 | : basic_iostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__t, __which, __a) {} |
| 1208 | |
| 1209 | # endif // _LIBCPP_STD_VER >= 26 |
| 1210 | |
| 1211 | basic_stringstream(const basic_stringstream&) = delete; |
| 1212 | _LIBCPP_HIDE_FROM_ABI basic_stringstream(basic_stringstream&& __rhs) |
| 1213 | : basic_iostream<_CharT, _Traits>(std::move(__rhs)), __sb_(std::move(__rhs.__sb_)) { |
| 1214 | basic_istream<_CharT, _Traits>::set_rdbuf(std::addressof(__sb_)); |
| 1215 | } |
| 1216 | |
| 1217 | // [stringstream.assign] Assign and swap: |
| 1218 | basic_stringstream& operator=(const basic_stringstream&) = delete; |
| 1219 | basic_stringstream& operator=(basic_stringstream&& __rhs) { |
| 1220 | basic_iostream<char_type, traits_type>::operator=(std::move(__rhs)); |
| 1221 | __sb_ = std::move(__rhs.__sb_); |
| 1222 | return *this; |
| 1223 | } |
| 1224 | _LIBCPP_HIDE_FROM_ABI void swap(basic_stringstream& __rhs) { |
| 1225 | basic_iostream<char_type, traits_type>::swap(__rhs); |
| 1226 | __sb_.swap(__rhs.__sb_); |
| 1227 | } |
| 1228 | |
| 1229 | // [stringstream.members] Member functions: |
| 1230 | _LIBCPP_HIDE_FROM_ABI basic_stringbuf<char_type, traits_type, allocator_type>* rdbuf() const { |
| 1231 | return const_cast<basic_stringbuf<char_type, traits_type, allocator_type>*>(std::addressof(__sb_)); |
| 1232 | } |
| 1233 | |
| 1234 | # if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_BUILDING_LIBRARY) |
| 1235 | _LIBCPP_HIDE_FROM_ABI string_type str() const { return __sb_.str(); } |
| 1236 | # else |
| 1237 | _LIBCPP_HIDE_FROM_ABI string_type str() const& { return __sb_.str(); } |
| 1238 | |
| 1239 | _LIBCPP_HIDE_FROM_ABI string_type str() && { return std::move(__sb_).str(); } |
| 1240 | # endif |
| 1241 | |
| 1242 | # if _LIBCPP_STD_VER >= 20 |
| 1243 | template <class _SAlloc> |
| 1244 | requires __is_allocator<_SAlloc>::value |
| 1245 | _LIBCPP_HIDE_FROM_ABI basic_string<char_type, traits_type, _SAlloc> str(const _SAlloc& __sa) const { |
| 1246 | return __sb_.str(__sa); |
| 1247 | } |
| 1248 | |
| 1249 | _LIBCPP_HIDE_FROM_ABI basic_string_view<char_type, traits_type> view() const noexcept { return __sb_.view(); } |
| 1250 | # endif // _LIBCPP_STD_VER >= 20 |
| 1251 | |
| 1252 | _LIBCPP_HIDE_FROM_ABI void str(const string_type& __s) { __sb_.str(__s); } |
| 1253 | |
| 1254 | # if _LIBCPP_STD_VER >= 20 |
| 1255 | template <class _SAlloc> |
| 1256 | _LIBCPP_HIDE_FROM_ABI void str(const basic_string<char_type, traits_type, _SAlloc>& __s) { |
| 1257 | __sb_.str(__s); |
| 1258 | } |
| 1259 | |
| 1260 | _LIBCPP_HIDE_FROM_ABI void str(string_type&& __s) { __sb_.str(std::move(__s)); } |
| 1261 | # endif // _LIBCPP_STD_VER >= 20 |
| 1262 | |
| 1263 | # if _LIBCPP_STD_VER >= 26 |
| 1264 | template <class _Tp> |
| 1265 | requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>> |
| 1266 | _LIBCPP_HIDE_FROM_ABI void str(const _Tp& __t) { |
| 1267 | rdbuf()->str(__t); |
| 1268 | } |
| 1269 | # endif // _LIBCPP_STD_VER >= 26 |
| 1270 | }; |
| 1271 | |
| 1272 | template <class _CharT, class _Traits, class _Allocator> |
| 1273 | inline _LIBCPP_HIDE_FROM_ABI void |
| 1274 | swap(basic_stringstream<_CharT, _Traits, _Allocator>& __x, basic_stringstream<_CharT, _Traits, _Allocator>& __y) { |
| 1275 | __x.swap(__y); |
| 1276 | } |
| 1277 | |
| 1278 | # if _LIBCPP_AVAILABILITY_HAS_ADDITIONAL_IOSTREAM_EXPLICIT_INSTANTIATIONS_1 |
| 1279 | extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_stringbuf<char>; |
| 1280 | extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_stringstream<char>; |
| 1281 | extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ostringstream<char>; |
| 1282 | extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_istringstream<char>; |
| 1283 | # endif |
| 1284 | |
| 1285 | _LIBCPP_END_NAMESPACE_STD |
| 1286 | |
| 1287 | _LIBCPP_POP_MACROS |
| 1288 | |
| 1289 | # endif // _LIBCPP_HAS_LOCALIZATION |
| 1290 | |
| 1291 | # if _LIBCPP_STD_VER <= 20 && !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) |
| 1292 | # include <ostream> |
| 1293 | # include <type_traits> |
| 1294 | # endif |
| 1295 | #endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS) |
| 1296 | |
| 1297 | #endif // _LIBCPP_SSTREAM |
| 1298 | |