| 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 <streambuf> |
| 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 | _LIBCPP_BEGIN_EXPLICIT_ABI_ANNOTATIONS |
| 342 | |
| 343 | // Class template basic_stringbuf [stringbuf] |
| 344 | |
| 345 | template <class _CharT, class _Traits, class _Allocator> |
| 346 | class basic_stringbuf : public basic_streambuf<_CharT, _Traits> { |
| 347 | public: |
| 348 | typedef _CharT char_type; |
| 349 | typedef _Traits traits_type; |
| 350 | typedef typename traits_type::int_type int_type; |
| 351 | typedef typename traits_type::pos_type pos_type; |
| 352 | typedef typename traits_type::off_type off_type; |
| 353 | typedef _Allocator allocator_type; |
| 354 | |
| 355 | typedef basic_string<char_type, traits_type, allocator_type> string_type; |
| 356 | |
| 357 | private: |
| 358 | string_type __str_; |
| 359 | mutable char_type* __hm_; |
| 360 | ios_base::openmode __mode_; |
| 361 | _LIBCPP_HIDE_FROM_ABI void __init_buf_ptrs(); |
| 362 | _LIBCPP_HIDE_FROM_ABI void __move_init(basic_stringbuf&& __rhs); |
| 363 | |
| 364 | public: |
| 365 | // [stringbuf.cons] constructors: |
| 366 | _LIBCPP_HIDE_FROM_ABI basic_stringbuf() : __hm_(nullptr), __mode_(ios_base::in | ios_base::out) { |
| 367 | // it is implementation-defined whether we initialize eback() & friends to nullptr, and libc++ doesn't |
| 368 | __init_buf_ptrs(); |
| 369 | } |
| 370 | |
| 371 | _LIBCPP_HIDE_FROM_ABI explicit basic_stringbuf(ios_base::openmode __wch) : __hm_(nullptr), __mode_(__wch) { |
| 372 | // it is implementation-defined whether we initialize eback() & friends to nullptr, and libc++ doesn't |
| 373 | __init_buf_ptrs(); |
| 374 | } |
| 375 | |
| 376 | _LIBCPP_HIDE_FROM_ABI explicit basic_stringbuf(const string_type& __s, |
| 377 | ios_base::openmode __wch = ios_base::in | ios_base::out) |
| 378 | : __str_(__s.get_allocator()), __hm_(nullptr), __mode_(__wch) { |
| 379 | str(__s); |
| 380 | } |
| 381 | |
| 382 | # if _LIBCPP_STD_VER >= 20 |
| 383 | _LIBCPP_HIDE_FROM_ABI explicit basic_stringbuf(const allocator_type& __a) |
| 384 | : basic_stringbuf(ios_base::in | ios_base::out, __a) {} |
| 385 | |
| 386 | _LIBCPP_HIDE_FROM_ABI basic_stringbuf(ios_base::openmode __wch, const allocator_type& __a) |
| 387 | : __str_(__a), __hm_(nullptr), __mode_(__wch) { |
| 388 | __init_buf_ptrs(); |
| 389 | } |
| 390 | |
| 391 | _LIBCPP_HIDE_FROM_ABI explicit basic_stringbuf(string_type&& __s, |
| 392 | ios_base::openmode __wch = ios_base::in | ios_base::out) |
| 393 | : __str_(std::move(__s)), __hm_(nullptr), __mode_(__wch) { |
| 394 | __init_buf_ptrs(); |
| 395 | } |
| 396 | |
| 397 | template <class _SAlloc> |
| 398 | _LIBCPP_HIDE_FROM_ABI |
| 399 | basic_stringbuf(const basic_string<char_type, traits_type, _SAlloc>& __s, const allocator_type& __a) |
| 400 | : basic_stringbuf(__s, ios_base::in | ios_base::out, __a) {} |
| 401 | |
| 402 | template <class _SAlloc> |
| 403 | _LIBCPP_HIDE_FROM_ABI basic_stringbuf( |
| 404 | const basic_string<char_type, traits_type, _SAlloc>& __s, ios_base::openmode __wch, const allocator_type& __a) |
| 405 | : __str_(__s, __a), __hm_(nullptr), __mode_(__wch) { |
| 406 | __init_buf_ptrs(); |
| 407 | } |
| 408 | |
| 409 | template <class _SAlloc> |
| 410 | requires(!is_same_v<_SAlloc, allocator_type>) |
| 411 | _LIBCPP_HIDE_FROM_ABI explicit basic_stringbuf(const basic_string<char_type, traits_type, _SAlloc>& __s, |
| 412 | ios_base::openmode __wch = ios_base::in | ios_base::out) |
| 413 | : __str_(__s), __hm_(nullptr), __mode_(__wch) { |
| 414 | __init_buf_ptrs(); |
| 415 | } |
| 416 | # endif // _LIBCPP_STD_VER >= 20 |
| 417 | |
| 418 | # if _LIBCPP_STD_VER >= 26 |
| 419 | |
| 420 | template <class _Tp> |
| 421 | requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>> |
| 422 | _LIBCPP_HIDE_FROM_ABI explicit basic_stringbuf(const _Tp& __t, |
| 423 | ios_base::openmode __which = ios_base::in | ios_base::out) |
| 424 | : basic_stringbuf(__t, __which, _Allocator()) {} |
| 425 | |
| 426 | template <class _Tp> |
| 427 | requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>> |
| 428 | _LIBCPP_HIDE_FROM_ABI basic_stringbuf(const _Tp& __t, const _Allocator& __a) |
| 429 | : basic_stringbuf(__t, ios_base::in | ios_base::out, __a) {} |
| 430 | |
| 431 | template <class _Tp> |
| 432 | requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>> |
| 433 | _LIBCPP_HIDE_FROM_ABI basic_stringbuf(const _Tp& __t, ios_base::openmode __which, const _Allocator& __a) |
| 434 | : __hm_(nullptr), __mode_(__which) { |
| 435 | basic_string_view<_CharT, _Traits> __sv = __t; |
| 436 | __str_ = string_type(__sv, __a); |
| 437 | __init_buf_ptrs(); |
| 438 | } |
| 439 | |
| 440 | # endif // _LIBCPP_STD_VER >= 26 |
| 441 | |
| 442 | basic_stringbuf(const basic_stringbuf&) = delete; |
| 443 | basic_stringbuf(basic_stringbuf&& __rhs) : __mode_(__rhs.__mode_) { __move_init(rhs: std::move(__rhs)); } |
| 444 | |
| 445 | # if _LIBCPP_STD_VER >= 20 |
| 446 | _LIBCPP_HIDE_FROM_ABI basic_stringbuf(basic_stringbuf&& __rhs, const allocator_type& __a) |
| 447 | : basic_stringbuf(__rhs.__mode_, __a) { |
| 448 | __move_init(rhs: std::move(__rhs)); |
| 449 | } |
| 450 | # endif |
| 451 | |
| 452 | // [stringbuf.assign] Assign and swap: |
| 453 | basic_stringbuf& operator=(const basic_stringbuf&) = delete; |
| 454 | basic_stringbuf& operator=(basic_stringbuf&& __rhs); |
| 455 | void swap(basic_stringbuf& __rhs) |
| 456 | # if _LIBCPP_STD_VER >= 20 |
| 457 | noexcept(allocator_traits<allocator_type>::propagate_on_container_swap::value || |
| 458 | allocator_traits<allocator_type>::is_always_equal::value) |
| 459 | # endif |
| 460 | ; |
| 461 | |
| 462 | // [stringbuf.members] Member functions: |
| 463 | |
| 464 | # if _LIBCPP_STD_VER >= 20 |
| 465 | [[nodiscard]] _LIBCPP_HIDE_FROM_ABI allocator_type get_allocator() const noexcept { return __str_.get_allocator(); } |
| 466 | # endif |
| 467 | |
| 468 | # if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_BUILDING_LIBRARY) |
| 469 | [[__nodiscard__]] string_type str() const; |
| 470 | # else |
| 471 | [[nodiscard]] _LIBCPP_HIDE_FROM_ABI string_type str() const& { return str(__str_.get_allocator()); } |
| 472 | |
| 473 | [[nodiscard]] _LIBCPP_HIDE_FROM_ABI string_type str() && { |
| 474 | const basic_string_view<_CharT, _Traits> __view = view(); |
| 475 | typename string_type::size_type __pos = __view.empty() ? 0 : __view.data() - __str_.data(); |
| 476 | // In C++23, this is just string_type(std::move(__str_), __pos, __view.size(), __str_.get_allocator()); |
| 477 | // But we need something that works in C++20 also. |
| 478 | string_type __result(std::move(__str_), __str_.get_allocator()); |
| 479 | __result.resize(__pos + __view.size()); |
| 480 | __result.erase(0, __pos); |
| 481 | __init_buf_ptrs(); |
| 482 | return __result; |
| 483 | } |
| 484 | # endif // _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_BUILDING_LIBRARY) |
| 485 | |
| 486 | # if _LIBCPP_STD_VER >= 20 |
| 487 | template <class _SAlloc> |
| 488 | requires __is_allocator_v<_SAlloc> |
| 489 | [[nodiscard]] _LIBCPP_HIDE_FROM_ABI basic_string<char_type, traits_type, _SAlloc> str(const _SAlloc& __sa) const { |
| 490 | return basic_string<_CharT, _Traits, _SAlloc>(view(), __sa); |
| 491 | } |
| 492 | |
| 493 | [[nodiscard]] _LIBCPP_HIDE_FROM_ABI basic_string_view<char_type, traits_type> view() const noexcept; |
| 494 | # endif // _LIBCPP_STD_VER >= 20 |
| 495 | |
| 496 | void str(const string_type& __s) { |
| 497 | __str_ = __s; |
| 498 | __init_buf_ptrs(); |
| 499 | } |
| 500 | |
| 501 | # if _LIBCPP_STD_VER >= 20 |
| 502 | template <class _SAlloc> |
| 503 | requires(!is_same_v<_SAlloc, allocator_type>) |
| 504 | _LIBCPP_HIDE_FROM_ABI void str(const basic_string<char_type, traits_type, _SAlloc>& __s) { |
| 505 | __str_ = __s; |
| 506 | __init_buf_ptrs(); |
| 507 | } |
| 508 | |
| 509 | _LIBCPP_HIDE_FROM_ABI void str(string_type&& __s) { |
| 510 | __str_ = std::move(__s); |
| 511 | __init_buf_ptrs(); |
| 512 | } |
| 513 | # endif // _LIBCPP_STD_VER >= 20 |
| 514 | |
| 515 | # if _LIBCPP_STD_VER >= 26 |
| 516 | |
| 517 | template <class _Tp> |
| 518 | requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>> |
| 519 | _LIBCPP_HIDE_FROM_ABI void str(const _Tp& __t) { |
| 520 | basic_string_view<_CharT, _Traits> __sv = __t; |
| 521 | __str_ = __sv; |
| 522 | __init_buf_ptrs(); |
| 523 | } |
| 524 | |
| 525 | # endif // _LIBCPP_STD_VER >= 26 |
| 526 | |
| 527 | protected: |
| 528 | // [stringbuf.virtuals] Overridden virtual functions: |
| 529 | int_type underflow() override; |
| 530 | int_type pbackfail(int_type __c = traits_type::eof()) override; |
| 531 | int_type overflow(int_type __c = traits_type::eof()) override; |
| 532 | pos_type |
| 533 | seekoff(off_type __off, ios_base::seekdir __way, ios_base::openmode __wch = ios_base::in | ios_base::out) override; |
| 534 | _LIBCPP_HIDE_FROM_ABI_VIRTUAL |
| 535 | pos_type seekpos(pos_type __sp, ios_base::openmode __wch = ios_base::in | ios_base::out) override { |
| 536 | return seekoff(off: __sp, way: ios_base::beg, __wch); |
| 537 | } |
| 538 | }; |
| 539 | |
| 540 | template <class _CharT, class _Traits, class _Allocator> |
| 541 | _LIBCPP_HIDE_FROM_ABI void basic_stringbuf<_CharT, _Traits, _Allocator>::__move_init(basic_stringbuf&& __rhs) { |
| 542 | char_type* __p = const_cast<char_type*>(__rhs.__str_.data()); |
| 543 | ptrdiff_t __binp = -1; |
| 544 | ptrdiff_t __ninp = -1; |
| 545 | ptrdiff_t __einp = -1; |
| 546 | if (__rhs.eback() != nullptr) { |
| 547 | __binp = __rhs.eback() - __p; |
| 548 | __ninp = __rhs.gptr() - __p; |
| 549 | __einp = __rhs.egptr() - __p; |
| 550 | } |
| 551 | ptrdiff_t __bout = -1; |
| 552 | ptrdiff_t __nout = -1; |
| 553 | ptrdiff_t __eout = -1; |
| 554 | if (__rhs.pbase() != nullptr) { |
| 555 | __bout = __rhs.pbase() - __p; |
| 556 | __nout = __rhs.pptr() - __p; |
| 557 | __eout = __rhs.epptr() - __p; |
| 558 | } |
| 559 | ptrdiff_t __hm = __rhs.__hm_ == nullptr ? -1 : __rhs.__hm_ - __p; |
| 560 | __str_ = std::move(__rhs.__str_); |
| 561 | __p = const_cast<char_type*>(__str_.data()); |
| 562 | if (__binp != -1) |
| 563 | this->setg(__p + __binp, __p + __ninp, __p + __einp); |
| 564 | if (__bout != -1) { |
| 565 | this->setp(__p + __bout, __p + __eout); |
| 566 | this->__pbump(__nout); |
| 567 | } |
| 568 | __hm_ = __hm == -1 ? nullptr : __p + __hm; |
| 569 | __p = const_cast<char_type*>(__rhs.__str_.data()); |
| 570 | __rhs.setg(__p, __p, __p); |
| 571 | __rhs.setp(__p, __p); |
| 572 | __rhs.__hm_ = __p; |
| 573 | this->pubimbue(__rhs.getloc()); |
| 574 | } |
| 575 | |
| 576 | template <class _CharT, class _Traits, class _Allocator> |
| 577 | basic_stringbuf<_CharT, _Traits, _Allocator>& |
| 578 | basic_stringbuf<_CharT, _Traits, _Allocator>::operator=(basic_stringbuf&& __rhs) { |
| 579 | char_type* __p = const_cast<char_type*>(__rhs.__str_.data()); |
| 580 | ptrdiff_t __binp = -1; |
| 581 | ptrdiff_t __ninp = -1; |
| 582 | ptrdiff_t __einp = -1; |
| 583 | if (__rhs.eback() != nullptr) { |
| 584 | __binp = __rhs.eback() - __p; |
| 585 | __ninp = __rhs.gptr() - __p; |
| 586 | __einp = __rhs.egptr() - __p; |
| 587 | } |
| 588 | ptrdiff_t __bout = -1; |
| 589 | ptrdiff_t __nout = -1; |
| 590 | ptrdiff_t __eout = -1; |
| 591 | if (__rhs.pbase() != nullptr) { |
| 592 | __bout = __rhs.pbase() - __p; |
| 593 | __nout = __rhs.pptr() - __p; |
| 594 | __eout = __rhs.epptr() - __p; |
| 595 | } |
| 596 | ptrdiff_t __hm = __rhs.__hm_ == nullptr ? -1 : __rhs.__hm_ - __p; |
| 597 | __str_ = std::move(__rhs.__str_); |
| 598 | __p = const_cast<char_type*>(__str_.data()); |
| 599 | if (__binp != -1) |
| 600 | this->setg(__p + __binp, __p + __ninp, __p + __einp); |
| 601 | else |
| 602 | this->setg(nullptr, nullptr, nullptr); |
| 603 | if (__bout != -1) { |
| 604 | this->setp(__p + __bout, __p + __eout); |
| 605 | this->__pbump(__nout); |
| 606 | } else |
| 607 | this->setp(nullptr, nullptr); |
| 608 | |
| 609 | __hm_ = __hm == -1 ? nullptr : __p + __hm; |
| 610 | __mode_ = __rhs.__mode_; |
| 611 | __p = const_cast<char_type*>(__rhs.__str_.data()); |
| 612 | __rhs.setg(__p, __p, __p); |
| 613 | __rhs.setp(__p, __p); |
| 614 | __rhs.__hm_ = __p; |
| 615 | this->pubimbue(__rhs.getloc()); |
| 616 | return *this; |
| 617 | } |
| 618 | |
| 619 | template <class _CharT, class _Traits, class _Allocator> |
| 620 | void basic_stringbuf<_CharT, _Traits, _Allocator>::swap(basic_stringbuf& __rhs) |
| 621 | # if _LIBCPP_STD_VER >= 20 |
| 622 | noexcept(allocator_traits<_Allocator>::propagate_on_container_swap::value || |
| 623 | allocator_traits<_Allocator>::is_always_equal::value) |
| 624 | # endif |
| 625 | { |
| 626 | char_type* __p = const_cast<char_type*>(__rhs.__str_.data()); |
| 627 | ptrdiff_t __rbinp = -1; |
| 628 | ptrdiff_t __rninp = -1; |
| 629 | ptrdiff_t __reinp = -1; |
| 630 | if (__rhs.eback() != nullptr) { |
| 631 | __rbinp = __rhs.eback() - __p; |
| 632 | __rninp = __rhs.gptr() - __p; |
| 633 | __reinp = __rhs.egptr() - __p; |
| 634 | } |
| 635 | ptrdiff_t __rbout = -1; |
| 636 | ptrdiff_t __rnout = -1; |
| 637 | ptrdiff_t __reout = -1; |
| 638 | if (__rhs.pbase() != nullptr) { |
| 639 | __rbout = __rhs.pbase() - __p; |
| 640 | __rnout = __rhs.pptr() - __p; |
| 641 | __reout = __rhs.epptr() - __p; |
| 642 | } |
| 643 | ptrdiff_t __rhm = __rhs.__hm_ == nullptr ? -1 : __rhs.__hm_ - __p; |
| 644 | __p = const_cast<char_type*>(__str_.data()); |
| 645 | ptrdiff_t __lbinp = -1; |
| 646 | ptrdiff_t __lninp = -1; |
| 647 | ptrdiff_t __leinp = -1; |
| 648 | if (this->eback() != nullptr) { |
| 649 | __lbinp = this->eback() - __p; |
| 650 | __lninp = this->gptr() - __p; |
| 651 | __leinp = this->egptr() - __p; |
| 652 | } |
| 653 | ptrdiff_t __lbout = -1; |
| 654 | ptrdiff_t __lnout = -1; |
| 655 | ptrdiff_t __leout = -1; |
| 656 | if (this->pbase() != nullptr) { |
| 657 | __lbout = this->pbase() - __p; |
| 658 | __lnout = this->pptr() - __p; |
| 659 | __leout = this->epptr() - __p; |
| 660 | } |
| 661 | ptrdiff_t __lhm = __hm_ == nullptr ? -1 : __hm_ - __p; |
| 662 | std::swap(x&: __mode_, y&: __rhs.__mode_); |
| 663 | __str_.swap(__rhs.__str_); |
| 664 | __p = const_cast<char_type*>(__str_.data()); |
| 665 | if (__rbinp != -1) |
| 666 | this->setg(__p + __rbinp, __p + __rninp, __p + __reinp); |
| 667 | else |
| 668 | this->setg(nullptr, nullptr, nullptr); |
| 669 | if (__rbout != -1) { |
| 670 | this->setp(__p + __rbout, __p + __reout); |
| 671 | this->__pbump(__rnout); |
| 672 | } else |
| 673 | this->setp(nullptr, nullptr); |
| 674 | __hm_ = __rhm == -1 ? nullptr : __p + __rhm; |
| 675 | __p = const_cast<char_type*>(__rhs.__str_.data()); |
| 676 | if (__lbinp != -1) |
| 677 | __rhs.setg(__p + __lbinp, __p + __lninp, __p + __leinp); |
| 678 | else |
| 679 | __rhs.setg(nullptr, nullptr, nullptr); |
| 680 | if (__lbout != -1) { |
| 681 | __rhs.setp(__p + __lbout, __p + __leout); |
| 682 | __rhs.__pbump(__lnout); |
| 683 | } else |
| 684 | __rhs.setp(nullptr, nullptr); |
| 685 | __rhs.__hm_ = __lhm == -1 ? nullptr : __p + __lhm; |
| 686 | locale __tl = __rhs.getloc(); |
| 687 | __rhs.pubimbue(this->getloc()); |
| 688 | this->pubimbue(__tl); |
| 689 | } |
| 690 | |
| 691 | template <class _CharT, class _Traits, class _Allocator> |
| 692 | inline _LIBCPP_HIDE_FROM_ABI void |
| 693 | swap(basic_stringbuf<_CharT, _Traits, _Allocator>& __x, basic_stringbuf<_CharT, _Traits, _Allocator>& __y) |
| 694 | # if _LIBCPP_STD_VER >= 20 |
| 695 | noexcept(noexcept(__x.swap(__y))) |
| 696 | # endif |
| 697 | { |
| 698 | __x.swap(__y); |
| 699 | } |
| 700 | |
| 701 | # if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_BUILDING_LIBRARY) |
| 702 | template <class _CharT, class _Traits, class _Allocator> |
| 703 | basic_string<_CharT, _Traits, _Allocator> basic_stringbuf<_CharT, _Traits, _Allocator>::str() const { |
| 704 | if (__mode_ & ios_base::out) { |
| 705 | if (__hm_ < this->pptr()) |
| 706 | __hm_ = this->pptr(); |
| 707 | return string_type(this->pbase(), __hm_, __str_.get_allocator()); |
| 708 | } else if (__mode_ & ios_base::in) |
| 709 | return string_type(this->eback(), this->egptr(), __str_.get_allocator()); |
| 710 | return string_type(__str_.get_allocator()); |
| 711 | } |
| 712 | # endif // _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_BUILDING_LIBRARY) |
| 713 | |
| 714 | template <class _CharT, class _Traits, class _Allocator> |
| 715 | _LIBCPP_HIDE_FROM_ABI void basic_stringbuf<_CharT, _Traits, _Allocator>::__init_buf_ptrs() { |
| 716 | __hm_ = nullptr; |
| 717 | char_type* __data = const_cast<char_type*>(__str_.data()); |
| 718 | typename string_type::size_type __sz = __str_.size(); |
| 719 | if (__mode_ & ios_base::in) { |
| 720 | __hm_ = __data + __sz; |
| 721 | this->setg(__data, __data, __hm_); |
| 722 | } |
| 723 | if (__mode_ & ios_base::out) { |
| 724 | __hm_ = __data + __sz; |
| 725 | __str_.resize(__str_.capacity()); |
| 726 | this->setp(__data, __data + __str_.size()); |
| 727 | if (__mode_ & (ios_base::app | ios_base::ate)) { |
| 728 | while (__sz > INT_MAX) { |
| 729 | this->pbump(INT_MAX); |
| 730 | __sz -= INT_MAX; |
| 731 | } |
| 732 | if (__sz > 0) |
| 733 | this->pbump(__sz); |
| 734 | } |
| 735 | } |
| 736 | } |
| 737 | |
| 738 | # if _LIBCPP_STD_VER >= 20 |
| 739 | template <class _CharT, class _Traits, class _Allocator> |
| 740 | _LIBCPP_HIDE_FROM_ABI basic_string_view<_CharT, _Traits> |
| 741 | basic_stringbuf<_CharT, _Traits, _Allocator>::view() const noexcept { |
| 742 | if (__mode_ & ios_base::out) { |
| 743 | if (__hm_ < this->pptr()) |
| 744 | __hm_ = this->pptr(); |
| 745 | return basic_string_view<_CharT, _Traits>(this->pbase(), __hm_); |
| 746 | } else if (__mode_ & ios_base::in) |
| 747 | return basic_string_view<_CharT, _Traits>(this->eback(), this->egptr()); |
| 748 | return basic_string_view<_CharT, _Traits>(); |
| 749 | } |
| 750 | # endif // _LIBCPP_STD_VER >= 20 |
| 751 | |
| 752 | template <class _CharT, class _Traits, class _Allocator> |
| 753 | typename basic_stringbuf<_CharT, _Traits, _Allocator>::int_type |
| 754 | basic_stringbuf<_CharT, _Traits, _Allocator>::underflow() { |
| 755 | if (__hm_ < this->pptr()) |
| 756 | __hm_ = this->pptr(); |
| 757 | if (__mode_ & ios_base::in) { |
| 758 | if (this->egptr() < __hm_) |
| 759 | this->setg(this->eback(), this->gptr(), __hm_); |
| 760 | if (this->gptr() < this->egptr()) |
| 761 | return traits_type::to_int_type(*this->gptr()); |
| 762 | } |
| 763 | return traits_type::eof(); |
| 764 | } |
| 765 | |
| 766 | template <class _CharT, class _Traits, class _Allocator> |
| 767 | typename basic_stringbuf<_CharT, _Traits, _Allocator>::int_type |
| 768 | basic_stringbuf<_CharT, _Traits, _Allocator>::pbackfail(int_type __c) { |
| 769 | if (__hm_ < this->pptr()) |
| 770 | __hm_ = this->pptr(); |
| 771 | if (this->eback() < this->gptr()) { |
| 772 | if (traits_type::eq_int_type(__c, traits_type::eof())) { |
| 773 | this->setg(this->eback(), this->gptr() - 1, __hm_); |
| 774 | return traits_type::not_eof(__c); |
| 775 | } |
| 776 | if ((__mode_ & ios_base::out) || traits_type::eq(traits_type::to_char_type(__c), this->gptr()[-1])) { |
| 777 | this->setg(this->eback(), this->gptr() - 1, __hm_); |
| 778 | *this->gptr() = traits_type::to_char_type(__c); |
| 779 | return __c; |
| 780 | } |
| 781 | } |
| 782 | return traits_type::eof(); |
| 783 | } |
| 784 | |
| 785 | template <class _CharT, class _Traits, class _Allocator> |
| 786 | typename basic_stringbuf<_CharT, _Traits, _Allocator>::int_type |
| 787 | basic_stringbuf<_CharT, _Traits, _Allocator>::overflow(int_type __c) { |
| 788 | if (!traits_type::eq_int_type(__c, traits_type::eof())) { |
| 789 | ptrdiff_t __ninp = this->gptr() - this->eback(); |
| 790 | if (this->pptr() == this->epptr()) { |
| 791 | if (!(__mode_ & ios_base::out)) |
| 792 | return traits_type::eof(); |
| 793 | # if _LIBCPP_HAS_EXCEPTIONS |
| 794 | try { |
| 795 | # endif // _LIBCPP_HAS_EXCEPTIONS |
| 796 | ptrdiff_t __nout = this->pptr() - this->pbase(); |
| 797 | ptrdiff_t __hm = __hm_ - this->pbase(); |
| 798 | __str_.push_back(char_type()); |
| 799 | __str_.resize(__str_.capacity()); |
| 800 | char_type* __p = const_cast<char_type*>(__str_.data()); |
| 801 | this->setp(__p, __p + __str_.size()); |
| 802 | this->__pbump(__nout); |
| 803 | __hm_ = this->pbase() + __hm; |
| 804 | # if _LIBCPP_HAS_EXCEPTIONS |
| 805 | } catch (...) { |
| 806 | return traits_type::eof(); |
| 807 | } |
| 808 | # endif // _LIBCPP_HAS_EXCEPTIONS |
| 809 | } |
| 810 | __hm_ = std::max(this->pptr() + 1, __hm_); |
| 811 | if (__mode_ & ios_base::in) { |
| 812 | char_type* __p = const_cast<char_type*>(__str_.data()); |
| 813 | this->setg(__p, __p + __ninp, __hm_); |
| 814 | } |
| 815 | return this->sputc(traits_type::to_char_type(__c)); |
| 816 | } |
| 817 | return traits_type::not_eof(__c); |
| 818 | } |
| 819 | |
| 820 | template <class _CharT, class _Traits, class _Allocator> |
| 821 | typename basic_stringbuf<_CharT, _Traits, _Allocator>::pos_type basic_stringbuf<_CharT, _Traits, _Allocator>::seekoff( |
| 822 | off_type __off, ios_base::seekdir __way, ios_base::openmode __wch) { |
| 823 | if (__hm_ < this->pptr()) |
| 824 | __hm_ = this->pptr(); |
| 825 | if ((__wch & (ios_base::in | ios_base::out)) == 0) |
| 826 | return pos_type(-1); |
| 827 | if ((__wch & (ios_base::in | ios_base::out)) == (ios_base::in | ios_base::out) && __way == ios_base::cur) |
| 828 | return pos_type(-1); |
| 829 | const ptrdiff_t __hm = __hm_ == nullptr ? 0 : __hm_ - __str_.data(); |
| 830 | off_type __noff; |
| 831 | switch (__way) { |
| 832 | case ios_base::beg: |
| 833 | __noff = 0; |
| 834 | break; |
| 835 | case ios_base::cur: |
| 836 | if (__wch & ios_base::in) |
| 837 | __noff = this->gptr() - this->eback(); |
| 838 | else |
| 839 | __noff = this->pptr() - this->pbase(); |
| 840 | break; |
| 841 | case ios_base::end: |
| 842 | __noff = __hm; |
| 843 | break; |
| 844 | default: |
| 845 | return pos_type(-1); |
| 846 | } |
| 847 | __noff += __off; |
| 848 | if (__noff < 0 || __hm < __noff) |
| 849 | return pos_type(-1); |
| 850 | if (__noff != 0) { |
| 851 | if ((__wch & ios_base::in) && this->gptr() == nullptr) |
| 852 | return pos_type(-1); |
| 853 | if ((__wch & ios_base::out) && this->pptr() == nullptr) |
| 854 | return pos_type(-1); |
| 855 | } |
| 856 | if (__wch & ios_base::in) |
| 857 | this->setg(this->eback(), this->eback() + __noff, __hm_); |
| 858 | if (__wch & ios_base::out) { |
| 859 | this->setp(this->pbase(), this->epptr()); |
| 860 | this->__pbump(__noff); |
| 861 | } |
| 862 | return pos_type(__noff); |
| 863 | } |
| 864 | |
| 865 | // Class template basic_istringstream [istringstream] |
| 866 | |
| 867 | template <class _CharT, class _Traits, class _Allocator> |
| 868 | class basic_istringstream : public basic_istream<_CharT, _Traits> { |
| 869 | public: |
| 870 | typedef _CharT char_type; |
| 871 | typedef _Traits traits_type; |
| 872 | typedef typename traits_type::int_type int_type; |
| 873 | typedef typename traits_type::pos_type pos_type; |
| 874 | typedef typename traits_type::off_type off_type; |
| 875 | typedef _Allocator allocator_type; |
| 876 | |
| 877 | typedef basic_string<char_type, traits_type, allocator_type> string_type; |
| 878 | |
| 879 | private: |
| 880 | basic_stringbuf<char_type, traits_type, allocator_type> __sb_; |
| 881 | |
| 882 | public: |
| 883 | // [istringstream.cons] Constructors: |
| 884 | _LIBCPP_HIDE_FROM_ABI basic_istringstream() |
| 885 | : basic_istream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(ios_base::in) {} |
| 886 | |
| 887 | _LIBCPP_HIDE_FROM_ABI explicit basic_istringstream(ios_base::openmode __wch) |
| 888 | : basic_istream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__wch | ios_base::in) {} |
| 889 | |
| 890 | _LIBCPP_HIDE_FROM_ABI explicit basic_istringstream(const string_type& __s, ios_base::openmode __wch = ios_base::in) |
| 891 | : basic_istream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__s, __wch | ios_base::in) {} |
| 892 | |
| 893 | # if _LIBCPP_STD_VER >= 20 |
| 894 | _LIBCPP_HIDE_FROM_ABI basic_istringstream(ios_base::openmode __wch, const _Allocator& __a) |
| 895 | : basic_istream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__wch | ios_base::in, __a) {} |
| 896 | |
| 897 | _LIBCPP_HIDE_FROM_ABI explicit basic_istringstream(string_type&& __s, ios_base::openmode __wch = ios_base::in) |
| 898 | : basic_istream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(std::move(__s), __wch | ios_base::in) {} |
| 899 | |
| 900 | template <class _SAlloc> |
| 901 | _LIBCPP_HIDE_FROM_ABI basic_istringstream(const basic_string<_CharT, _Traits, _SAlloc>& __s, const _Allocator& __a) |
| 902 | : basic_istringstream(__s, ios_base::in, __a) {} |
| 903 | |
| 904 | template <class _SAlloc> |
| 905 | _LIBCPP_HIDE_FROM_ABI basic_istringstream( |
| 906 | const basic_string<_CharT, _Traits, _SAlloc>& __s, ios_base::openmode __wch, const _Allocator& __a) |
| 907 | : basic_istream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__s, __wch | ios_base::in, __a) {} |
| 908 | |
| 909 | template <class _SAlloc> |
| 910 | _LIBCPP_HIDE_FROM_ABI explicit basic_istringstream(const basic_string<_CharT, _Traits, _SAlloc>& __s, |
| 911 | ios_base::openmode __wch = ios_base::in) |
| 912 | : basic_istream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__s, __wch | ios_base::in) {} |
| 913 | # endif // _LIBCPP_STD_VER >= 20 |
| 914 | |
| 915 | # if _LIBCPP_STD_VER >= 26 |
| 916 | |
| 917 | template <class _Tp> |
| 918 | requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>> |
| 919 | _LIBCPP_HIDE_FROM_ABI explicit basic_istringstream(const _Tp& __t, ios_base::openmode __which = ios_base::in) |
| 920 | : basic_istringstream(__t, __which, _Allocator()) {} |
| 921 | |
| 922 | template <class _Tp> |
| 923 | requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>> |
| 924 | _LIBCPP_HIDE_FROM_ABI basic_istringstream(const _Tp& __t, const _Allocator& __a) |
| 925 | : basic_istringstream(__t, ios_base::in, __a) {} |
| 926 | |
| 927 | template <class _Tp> |
| 928 | requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>> |
| 929 | _LIBCPP_HIDE_FROM_ABI basic_istringstream(const _Tp& __t, ios_base::openmode __which, const _Allocator& __a) |
| 930 | : basic_istream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__t, __which | ios_base::in, __a) {} |
| 931 | |
| 932 | # endif // _LIBCPP_STD_VER >= 26 |
| 933 | |
| 934 | basic_istringstream(const basic_istringstream&) = delete; |
| 935 | _LIBCPP_HIDE_FROM_ABI basic_istringstream(basic_istringstream&& __rhs) |
| 936 | : basic_istream<_CharT, _Traits>(std::move(__rhs)), __sb_(std::move(__rhs.__sb_)) { |
| 937 | basic_istream<_CharT, _Traits>::set_rdbuf(std::addressof(__sb_)); |
| 938 | } |
| 939 | |
| 940 | // [istringstream.assign] Assign and swap: |
| 941 | basic_istringstream& operator=(const basic_istringstream&) = delete; |
| 942 | basic_istringstream& operator=(basic_istringstream&& __rhs) { |
| 943 | basic_istream<char_type, traits_type>::operator=(std::move(__rhs)); |
| 944 | __sb_ = std::move(__rhs.__sb_); |
| 945 | return *this; |
| 946 | } |
| 947 | _LIBCPP_HIDE_FROM_ABI void swap(basic_istringstream& __rhs) { |
| 948 | basic_istream<char_type, traits_type>::swap(__rhs); |
| 949 | __sb_.swap(__rhs.__sb_); |
| 950 | } |
| 951 | |
| 952 | // [istringstream.members] Member functions: |
| 953 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI basic_stringbuf<char_type, traits_type, allocator_type>* rdbuf() const { |
| 954 | return const_cast<basic_stringbuf<char_type, traits_type, allocator_type>*>(std::addressof(__sb_)); |
| 955 | } |
| 956 | |
| 957 | # if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_BUILDING_LIBRARY) |
| 958 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI string_type str() const { return __sb_.str(); } |
| 959 | # else |
| 960 | [[nodiscard]] _LIBCPP_HIDE_FROM_ABI string_type str() const& { return __sb_.str(); } |
| 961 | |
| 962 | [[nodiscard]] _LIBCPP_HIDE_FROM_ABI string_type str() && { return std::move(__sb_).str(); } |
| 963 | # endif |
| 964 | |
| 965 | # if _LIBCPP_STD_VER >= 20 |
| 966 | template <class _SAlloc> |
| 967 | requires __is_allocator_v<_SAlloc> |
| 968 | [[nodiscard]] _LIBCPP_HIDE_FROM_ABI basic_string<char_type, traits_type, _SAlloc> str(const _SAlloc& __sa) const { |
| 969 | return __sb_.str(__sa); |
| 970 | } |
| 971 | |
| 972 | [[nodiscard]] _LIBCPP_HIDE_FROM_ABI basic_string_view<char_type, traits_type> view() const noexcept { |
| 973 | return __sb_.view(); |
| 974 | } |
| 975 | # endif // _LIBCPP_STD_VER >= 20 |
| 976 | |
| 977 | _LIBCPP_HIDE_FROM_ABI void str(const string_type& __s) { __sb_.str(__s); } |
| 978 | |
| 979 | # if _LIBCPP_STD_VER >= 20 |
| 980 | template <class _SAlloc> |
| 981 | _LIBCPP_HIDE_FROM_ABI void str(const basic_string<char_type, traits_type, _SAlloc>& __s) { |
| 982 | __sb_.str(__s); |
| 983 | } |
| 984 | |
| 985 | _LIBCPP_HIDE_FROM_ABI void str(string_type&& __s) { __sb_.str(std::move(__s)); } |
| 986 | # endif // _LIBCPP_STD_VER >= 20 |
| 987 | |
| 988 | # if _LIBCPP_STD_VER >= 26 |
| 989 | template <class _Tp> |
| 990 | requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>> |
| 991 | _LIBCPP_HIDE_FROM_ABI void str(const _Tp& __t) { |
| 992 | rdbuf()->str(__t); |
| 993 | } |
| 994 | # endif // _LIBCPP_STD_VER >= 26 |
| 995 | }; |
| 996 | |
| 997 | template <class _CharT, class _Traits, class _Allocator> |
| 998 | inline _LIBCPP_HIDE_FROM_ABI void |
| 999 | swap(basic_istringstream<_CharT, _Traits, _Allocator>& __x, basic_istringstream<_CharT, _Traits, _Allocator>& __y) { |
| 1000 | __x.swap(__y); |
| 1001 | } |
| 1002 | |
| 1003 | // Class template basic_ostringstream [ostringstream] |
| 1004 | |
| 1005 | template <class _CharT, class _Traits, class _Allocator> |
| 1006 | class basic_ostringstream : public basic_ostream<_CharT, _Traits> { |
| 1007 | public: |
| 1008 | typedef _CharT char_type; |
| 1009 | typedef _Traits traits_type; |
| 1010 | typedef typename traits_type::int_type int_type; |
| 1011 | typedef typename traits_type::pos_type pos_type; |
| 1012 | typedef typename traits_type::off_type off_type; |
| 1013 | typedef _Allocator allocator_type; |
| 1014 | |
| 1015 | typedef basic_string<char_type, traits_type, allocator_type> string_type; |
| 1016 | |
| 1017 | private: |
| 1018 | basic_stringbuf<char_type, traits_type, allocator_type> __sb_; |
| 1019 | |
| 1020 | public: |
| 1021 | // [ostringstream.cons] Constructors: |
| 1022 | _LIBCPP_HIDE_FROM_ABI basic_ostringstream() |
| 1023 | : basic_ostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(ios_base::out) {} |
| 1024 | |
| 1025 | _LIBCPP_HIDE_FROM_ABI explicit basic_ostringstream(ios_base::openmode __wch) |
| 1026 | : basic_ostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__wch | ios_base::out) {} |
| 1027 | |
| 1028 | _LIBCPP_HIDE_FROM_ABI explicit basic_ostringstream(const string_type& __s, ios_base::openmode __wch = ios_base::out) |
| 1029 | : basic_ostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__s, __wch | ios_base::out) {} |
| 1030 | |
| 1031 | # if _LIBCPP_STD_VER >= 20 |
| 1032 | _LIBCPP_HIDE_FROM_ABI basic_ostringstream(ios_base::openmode __wch, const _Allocator& __a) |
| 1033 | : basic_ostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__wch | ios_base::out, __a) {} |
| 1034 | |
| 1035 | _LIBCPP_HIDE_FROM_ABI explicit basic_ostringstream(string_type&& __s, ios_base::openmode __wch = ios_base::out) |
| 1036 | : basic_ostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(std::move(__s), __wch | ios_base::out) {} |
| 1037 | |
| 1038 | template <class _SAlloc> |
| 1039 | _LIBCPP_HIDE_FROM_ABI basic_ostringstream(const basic_string<_CharT, _Traits, _SAlloc>& __s, const _Allocator& __a) |
| 1040 | : basic_ostringstream(__s, ios_base::out, __a) {} |
| 1041 | |
| 1042 | template <class _SAlloc> |
| 1043 | _LIBCPP_HIDE_FROM_ABI basic_ostringstream( |
| 1044 | const basic_string<_CharT, _Traits, _SAlloc>& __s, ios_base::openmode __wch, const _Allocator& __a) |
| 1045 | : basic_ostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__s, __wch | ios_base::out, __a) {} |
| 1046 | |
| 1047 | template <class _SAlloc> |
| 1048 | requires(!is_same_v<_SAlloc, allocator_type>) |
| 1049 | _LIBCPP_HIDE_FROM_ABI explicit basic_ostringstream(const basic_string<_CharT, _Traits, _SAlloc>& __s, |
| 1050 | ios_base::openmode __wch = ios_base::out) |
| 1051 | : basic_ostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__s, __wch | ios_base::out) {} |
| 1052 | # endif // _LIBCPP_STD_VER >= 20 |
| 1053 | |
| 1054 | # if _LIBCPP_STD_VER >= 26 |
| 1055 | |
| 1056 | template <class _Tp> |
| 1057 | requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>> |
| 1058 | _LIBCPP_HIDE_FROM_ABI explicit basic_ostringstream(const _Tp& __t, ios_base::openmode __which = ios_base::out) |
| 1059 | : basic_ostringstream(__t, __which | ios_base::out, _Allocator()) {} |
| 1060 | |
| 1061 | template <class _Tp> |
| 1062 | requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>> |
| 1063 | _LIBCPP_HIDE_FROM_ABI basic_ostringstream(const _Tp& __t, const _Allocator& __a) |
| 1064 | : basic_ostringstream(__t, ios_base::out, __a) {} |
| 1065 | |
| 1066 | template <class _Tp> |
| 1067 | requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>> |
| 1068 | _LIBCPP_HIDE_FROM_ABI basic_ostringstream(const _Tp& __t, ios_base::openmode __which, const _Allocator& __a) |
| 1069 | : basic_ostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__t, __which | ios_base::out, __a) {} |
| 1070 | |
| 1071 | # endif // _LIBCPP_STD_VER >= 26 |
| 1072 | |
| 1073 | basic_ostringstream(const basic_ostringstream&) = delete; |
| 1074 | _LIBCPP_HIDE_FROM_ABI basic_ostringstream(basic_ostringstream&& __rhs) |
| 1075 | : basic_ostream<_CharT, _Traits>(std::move(__rhs)), __sb_(std::move(__rhs.__sb_)) { |
| 1076 | basic_ostream<_CharT, _Traits>::set_rdbuf(std::addressof(__sb_)); |
| 1077 | } |
| 1078 | |
| 1079 | // [ostringstream.assign] Assign and swap: |
| 1080 | basic_ostringstream& operator=(const basic_ostringstream&) = delete; |
| 1081 | basic_ostringstream& operator=(basic_ostringstream&& __rhs) { |
| 1082 | basic_ostream<char_type, traits_type>::operator=(std::move(__rhs)); |
| 1083 | __sb_ = std::move(__rhs.__sb_); |
| 1084 | return *this; |
| 1085 | } |
| 1086 | |
| 1087 | _LIBCPP_HIDE_FROM_ABI void swap(basic_ostringstream& __rhs) { |
| 1088 | basic_ostream<char_type, traits_type>::swap(__rhs); |
| 1089 | __sb_.swap(__rhs.__sb_); |
| 1090 | } |
| 1091 | |
| 1092 | // [ostringstream.members] Member functions: |
| 1093 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI basic_stringbuf<char_type, traits_type, allocator_type>* rdbuf() const { |
| 1094 | return const_cast<basic_stringbuf<char_type, traits_type, allocator_type>*>(std::addressof(__sb_)); |
| 1095 | } |
| 1096 | |
| 1097 | # if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_BUILDING_LIBRARY) |
| 1098 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI string_type str() const { return __sb_.str(); } |
| 1099 | # else |
| 1100 | [[nodiscard]] _LIBCPP_HIDE_FROM_ABI string_type str() const& { return __sb_.str(); } |
| 1101 | |
| 1102 | [[nodiscard]] _LIBCPP_HIDE_FROM_ABI string_type str() && { return std::move(__sb_).str(); } |
| 1103 | # endif |
| 1104 | |
| 1105 | # if _LIBCPP_STD_VER >= 20 |
| 1106 | template <class _SAlloc> |
| 1107 | requires __is_allocator_v<_SAlloc> |
| 1108 | [[nodiscard]] _LIBCPP_HIDE_FROM_ABI basic_string<char_type, traits_type, _SAlloc> str(const _SAlloc& __sa) const { |
| 1109 | return __sb_.str(__sa); |
| 1110 | } |
| 1111 | |
| 1112 | [[nodiscard]] _LIBCPP_HIDE_FROM_ABI basic_string_view<char_type, traits_type> view() const noexcept { |
| 1113 | return __sb_.view(); |
| 1114 | } |
| 1115 | # endif // _LIBCPP_STD_VER >= 20 |
| 1116 | |
| 1117 | _LIBCPP_HIDE_FROM_ABI void str(const string_type& __s) { __sb_.str(__s); } |
| 1118 | |
| 1119 | # if _LIBCPP_STD_VER >= 20 |
| 1120 | template <class _SAlloc> |
| 1121 | _LIBCPP_HIDE_FROM_ABI void str(const basic_string<char_type, traits_type, _SAlloc>& __s) { |
| 1122 | __sb_.str(__s); |
| 1123 | } |
| 1124 | |
| 1125 | _LIBCPP_HIDE_FROM_ABI void str(string_type&& __s) { __sb_.str(std::move(__s)); } |
| 1126 | # endif // _LIBCPP_STD_VER >= 20 |
| 1127 | |
| 1128 | # if _LIBCPP_STD_VER >= 26 |
| 1129 | template <class _Tp> |
| 1130 | requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>> |
| 1131 | _LIBCPP_HIDE_FROM_ABI void str(const _Tp& __t) { |
| 1132 | rdbuf()->str(__t); |
| 1133 | } |
| 1134 | # endif // _LIBCPP_STD_VER >= 26 |
| 1135 | }; |
| 1136 | |
| 1137 | template <class _CharT, class _Traits, class _Allocator> |
| 1138 | inline _LIBCPP_HIDE_FROM_ABI void |
| 1139 | swap(basic_ostringstream<_CharT, _Traits, _Allocator>& __x, basic_ostringstream<_CharT, _Traits, _Allocator>& __y) { |
| 1140 | __x.swap(__y); |
| 1141 | } |
| 1142 | |
| 1143 | // Class template basic_stringstream [stringstream] |
| 1144 | |
| 1145 | template <class _CharT, class _Traits, class _Allocator> |
| 1146 | class basic_stringstream : public basic_iostream<_CharT, _Traits> { |
| 1147 | public: |
| 1148 | typedef _CharT char_type; |
| 1149 | typedef _Traits traits_type; |
| 1150 | typedef typename traits_type::int_type int_type; |
| 1151 | typedef typename traits_type::pos_type pos_type; |
| 1152 | typedef typename traits_type::off_type off_type; |
| 1153 | typedef _Allocator allocator_type; |
| 1154 | |
| 1155 | typedef basic_string<char_type, traits_type, allocator_type> string_type; |
| 1156 | |
| 1157 | private: |
| 1158 | basic_stringbuf<char_type, traits_type, allocator_type> __sb_; |
| 1159 | |
| 1160 | public: |
| 1161 | // [stringstream.cons] constructors |
| 1162 | _LIBCPP_HIDE_FROM_ABI basic_stringstream() |
| 1163 | : basic_iostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(ios_base::in | ios_base::out) {} |
| 1164 | |
| 1165 | _LIBCPP_HIDE_FROM_ABI explicit basic_stringstream(ios_base::openmode __wch) |
| 1166 | : basic_iostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__wch) {} |
| 1167 | |
| 1168 | _LIBCPP_HIDE_FROM_ABI explicit basic_stringstream(const string_type& __s, |
| 1169 | ios_base::openmode __wch = ios_base::in | ios_base::out) |
| 1170 | : basic_iostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__s, __wch) {} |
| 1171 | |
| 1172 | # if _LIBCPP_STD_VER >= 20 |
| 1173 | _LIBCPP_HIDE_FROM_ABI basic_stringstream(ios_base::openmode __wch, const _Allocator& __a) |
| 1174 | : basic_iostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__wch, __a) {} |
| 1175 | |
| 1176 | _LIBCPP_HIDE_FROM_ABI explicit basic_stringstream(string_type&& __s, |
| 1177 | ios_base::openmode __wch = ios_base::out | ios_base::in) |
| 1178 | : basic_iostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(std::move(__s), __wch) {} |
| 1179 | |
| 1180 | template <class _SAlloc> |
| 1181 | _LIBCPP_HIDE_FROM_ABI basic_stringstream(const basic_string<_CharT, _Traits, _SAlloc>& __s, const _Allocator& __a) |
| 1182 | : basic_stringstream(__s, ios_base::out | ios_base::in, __a) {} |
| 1183 | |
| 1184 | template <class _SAlloc> |
| 1185 | _LIBCPP_HIDE_FROM_ABI |
| 1186 | basic_stringstream(const basic_string<_CharT, _Traits, _SAlloc>& __s, ios_base::openmode __wch, const _Allocator& __a) |
| 1187 | : basic_iostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__s, __wch, __a) {} |
| 1188 | |
| 1189 | template <class _SAlloc> |
| 1190 | requires(!is_same_v<_SAlloc, allocator_type>) |
| 1191 | _LIBCPP_HIDE_FROM_ABI explicit basic_stringstream(const basic_string<_CharT, _Traits, _SAlloc>& __s, |
| 1192 | ios_base::openmode __wch = ios_base::out | ios_base::in) |
| 1193 | : basic_iostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__s, __wch) {} |
| 1194 | # endif // _LIBCPP_STD_VER >= 20 |
| 1195 | |
| 1196 | # if _LIBCPP_STD_VER >= 26 |
| 1197 | |
| 1198 | template <class _Tp> |
| 1199 | requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>> |
| 1200 | _LIBCPP_HIDE_FROM_ABI explicit basic_stringstream(const _Tp& __t, |
| 1201 | ios_base::openmode __which = ios_base::out | ios_base::in) |
| 1202 | : basic_stringstream(__t, __which, _Allocator()) {} |
| 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, const _Allocator& __a) |
| 1207 | : basic_stringstream(__t, ios_base::out | ios_base::in, __a) {} |
| 1208 | |
| 1209 | template <class _Tp> |
| 1210 | requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>> |
| 1211 | _LIBCPP_HIDE_FROM_ABI basic_stringstream(const _Tp& __t, ios_base::openmode __which, const _Allocator& __a) |
| 1212 | : basic_iostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__t, __which, __a) {} |
| 1213 | |
| 1214 | # endif // _LIBCPP_STD_VER >= 26 |
| 1215 | |
| 1216 | basic_stringstream(const basic_stringstream&) = delete; |
| 1217 | _LIBCPP_HIDE_FROM_ABI basic_stringstream(basic_stringstream&& __rhs) |
| 1218 | : basic_iostream<_CharT, _Traits>(std::move(__rhs)), __sb_(std::move(__rhs.__sb_)) { |
| 1219 | basic_istream<_CharT, _Traits>::set_rdbuf(std::addressof(__sb_)); |
| 1220 | } |
| 1221 | |
| 1222 | // [stringstream.assign] Assign and swap: |
| 1223 | basic_stringstream& operator=(const basic_stringstream&) = delete; |
| 1224 | basic_stringstream& operator=(basic_stringstream&& __rhs) { |
| 1225 | basic_iostream<char_type, traits_type>::operator=(std::move(__rhs)); |
| 1226 | __sb_ = std::move(__rhs.__sb_); |
| 1227 | return *this; |
| 1228 | } |
| 1229 | _LIBCPP_HIDE_FROM_ABI void swap(basic_stringstream& __rhs) { |
| 1230 | basic_iostream<char_type, traits_type>::swap(__rhs); |
| 1231 | __sb_.swap(__rhs.__sb_); |
| 1232 | } |
| 1233 | |
| 1234 | // [stringstream.members] Member functions: |
| 1235 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI basic_stringbuf<char_type, traits_type, allocator_type>* rdbuf() const { |
| 1236 | return const_cast<basic_stringbuf<char_type, traits_type, allocator_type>*>(std::addressof(__sb_)); |
| 1237 | } |
| 1238 | |
| 1239 | # if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_BUILDING_LIBRARY) |
| 1240 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI string_type str() const { return __sb_.str(); } |
| 1241 | # else |
| 1242 | [[nodiscard]] _LIBCPP_HIDE_FROM_ABI string_type str() const& { return __sb_.str(); } |
| 1243 | |
| 1244 | [[nodiscard]] _LIBCPP_HIDE_FROM_ABI string_type str() && { return std::move(__sb_).str(); } |
| 1245 | # endif |
| 1246 | |
| 1247 | # if _LIBCPP_STD_VER >= 20 |
| 1248 | template <class _SAlloc> |
| 1249 | requires __is_allocator_v<_SAlloc> |
| 1250 | [[nodiscard]] _LIBCPP_HIDE_FROM_ABI basic_string<char_type, traits_type, _SAlloc> str(const _SAlloc& __sa) const { |
| 1251 | return __sb_.str(__sa); |
| 1252 | } |
| 1253 | |
| 1254 | [[nodiscard]] _LIBCPP_HIDE_FROM_ABI basic_string_view<char_type, traits_type> view() const noexcept { |
| 1255 | return __sb_.view(); |
| 1256 | } |
| 1257 | # endif // _LIBCPP_STD_VER >= 20 |
| 1258 | |
| 1259 | _LIBCPP_HIDE_FROM_ABI void str(const string_type& __s) { __sb_.str(__s); } |
| 1260 | |
| 1261 | # if _LIBCPP_STD_VER >= 20 |
| 1262 | template <class _SAlloc> |
| 1263 | _LIBCPP_HIDE_FROM_ABI void str(const basic_string<char_type, traits_type, _SAlloc>& __s) { |
| 1264 | __sb_.str(__s); |
| 1265 | } |
| 1266 | |
| 1267 | _LIBCPP_HIDE_FROM_ABI void str(string_type&& __s) { __sb_.str(std::move(__s)); } |
| 1268 | # endif // _LIBCPP_STD_VER >= 20 |
| 1269 | |
| 1270 | # if _LIBCPP_STD_VER >= 26 |
| 1271 | template <class _Tp> |
| 1272 | requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>> |
| 1273 | _LIBCPP_HIDE_FROM_ABI void str(const _Tp& __t) { |
| 1274 | rdbuf()->str(__t); |
| 1275 | } |
| 1276 | # endif // _LIBCPP_STD_VER >= 26 |
| 1277 | }; |
| 1278 | |
| 1279 | template <class _CharT, class _Traits, class _Allocator> |
| 1280 | inline _LIBCPP_HIDE_FROM_ABI void |
| 1281 | swap(basic_stringstream<_CharT, _Traits, _Allocator>& __x, basic_stringstream<_CharT, _Traits, _Allocator>& __y) { |
| 1282 | __x.swap(__y); |
| 1283 | } |
| 1284 | |
| 1285 | # if _LIBCPP_AVAILABILITY_HAS_ADDITIONAL_IOSTREAM_EXPLICIT_INSTANTIATIONS_1 |
| 1286 | extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_stringbuf<char>; |
| 1287 | extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_stringstream<char>; |
| 1288 | extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ostringstream<char>; |
| 1289 | extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_istringstream<char>; |
| 1290 | # endif |
| 1291 | |
| 1292 | _LIBCPP_END_EXPLICIT_ABI_ANNOTATIONS |
| 1293 | _LIBCPP_END_NAMESPACE_STD |
| 1294 | |
| 1295 | _LIBCPP_POP_MACROS |
| 1296 | |
| 1297 | # endif // _LIBCPP_HAS_LOCALIZATION |
| 1298 | |
| 1299 | # if defined(_LIBCPP_KEEP_TRANSITIVE_INCLUDES_LLVM23) && _LIBCPP_STD_VER <= 20 |
| 1300 | # include <ostream> |
| 1301 | # include <type_traits> |
| 1302 | # endif |
| 1303 | #endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS) |
| 1304 | |
| 1305 | #endif // _LIBCPP_SSTREAM |
| 1306 | |