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