Warning, /include/c++/v1/sstream is written in an unsupported language. File is not indexed.
0001 // -*- C++ -*-
0002 //===----------------------------------------------------------------------===//
0003 //
0004 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0005 // See https://llvm.org/LICENSE.txt for license information.
0006 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0007 //
0008 //===----------------------------------------------------------------------===//
0009
0010 #ifndef _LIBCPP_SSTREAM
0011 #define _LIBCPP_SSTREAM
0012
0013 // clang-format off
0014
0015 /*
0016 sstream synopsis [sstream.syn]
0017
0018 // Class template basic_stringbuf [stringbuf]
0019 template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> >
0020 class basic_stringbuf
0021 : public basic_streambuf<charT, traits>
0022 {
0023 public:
0024 typedef charT char_type;
0025 typedef traits traits_type;
0026 typedef typename traits_type::int_type int_type;
0027 typedef typename traits_type::pos_type pos_type;
0028 typedef typename traits_type::off_type off_type;
0029 typedef Allocator allocator_type;
0030
0031 // [stringbuf.cons] constructors:
0032 explicit basic_stringbuf(ios_base::openmode which = ios_base::in | ios_base::out); // before C++20
0033 basic_stringbuf() : basic_stringbuf(ios_base::in | ios_base::out) {} // C++20
0034 explicit basic_stringbuf(ios_base::openmode which); // C++20
0035 explicit basic_stringbuf(const basic_string<char_type, traits_type, allocator_type>& s,
0036 ios_base::openmode which = ios_base::in | ios_base::out);
0037 explicit basic_stringbuf(const allocator_type& a)
0038 : basic_stringbuf(ios_base::in | ios_base::out, a) {} // C++20
0039 basic_stringbuf(ios_base::openmode which, const allocator_type& a); // C++20
0040 explicit basic_stringbuf(basic_string<char_type, traits_type, allocator_type>&& s,
0041 ios_base::openmode which = ios_base::in | ios_base::out); // C++20
0042 template <class SAlloc>
0043 basic_stringbuf(const basic_string<char_type, traits_type, SAlloc>& s, const allocator_type& a)
0044 : basic_stringbuf(s, ios_base::in | ios_base::out, a) {} // C++20
0045 template <class SAlloc>
0046 basic_stringbuf(const basic_string<char_type, traits_type, SAlloc>& s,
0047 ios_base::openmode which, const allocator_type& a); // C++20
0048 template <class SAlloc>
0049 explicit basic_stringbuf(const basic_string<char_type, traits_type, SAlloc>& s,
0050 ios_base::openmode which = ios_base::in | ios_base::out); // C++20
0051 template<class T>
0052 explicit basic_stringbuf(const T& t,
0053 ios_base::openmode which = ios_base::in | ios_base::out); // Since C++26
0054 template<class T>
0055 basic_stringbuf(const T& t, const Allocator& a); // Since C++26
0056 template<class T>
0057 basic_stringbuf(const T& t, ios_base::openmode which, const Allocator& a); // Since C++26
0058 basic_stringbuf(const basic_stringbuf&) = delete;
0059 basic_stringbuf(basic_stringbuf&& rhs);
0060 basic_stringbuf(basic_stringbuf&& rhs, const allocator_type& a); // C++20
0061
0062 // [stringbuf.assign] Assign and swap:
0063 basic_stringbuf& operator=(const basic_stringbuf&) = delete;
0064 basic_stringbuf& operator=(basic_stringbuf&& rhs);
0065 void swap(basic_stringbuf& rhs) noexcept(see below); // conditionally noexcept since C++20
0066
0067 // [stringbuf.members] Member functions:
0068 allocator_type get_allocator() const noexcept; // C++20
0069 basic_string<char_type, traits_type, allocator_type> str() const; // before C++20
0070 basic_string<char_type, traits_type, allocator_type> str() const &; // C++20
0071 template <class SAlloc>
0072 basic_string<char_type, traits_type, SAlloc> str(const SAlloc& sa) const; // C++20
0073 basic_string<char_type, traits_type, allocator_type> str() &&; // C++20
0074 basic_string_view<char_type, traits_type> view() const noexcept; // C++20
0075 void str(const basic_string<char_type, traits_type, allocator_type>& s);
0076 template <class SAlloc>
0077 void str(const basic_string<char_type, traits_type, SAlloc>& s); // C++20
0078 void str(basic_string<char_type, traits_type, allocator_type>&& s); // C++20
0079 template<class T>
0080 void str(const T& t); // Since C++26
0081
0082 protected:
0083 // [stringbuf.virtuals] Overridden virtual functions:
0084 virtual int_type underflow();
0085 virtual int_type pbackfail(int_type c = traits_type::eof());
0086 virtual int_type overflow (int_type c = traits_type::eof());
0087 virtual basic_streambuf<char_type, traits_type>* setbuf(char_type*, streamsize);
0088 virtual pos_type seekoff(off_type off, ios_base::seekdir way,
0089 ios_base::openmode which = ios_base::in | ios_base::out);
0090 virtual pos_type seekpos(pos_type sp,
0091 ios_base::openmode which = ios_base::in | ios_base::out);
0092 };
0093
0094 // [stringbuf.assign] non member swap
0095 template <class charT, class traits, class Allocator>
0096 void swap(basic_stringbuf<charT, traits, Allocator>& x,
0097 basic_stringbuf<charT, traits, Allocator>& y); // conditionally noexcept since C++20
0098
0099 typedef basic_stringbuf<char> stringbuf;
0100 typedef basic_stringbuf<wchar_t> wstringbuf;
0101
0102 // Class template basic_istringstream [istringstream]
0103 template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> >
0104 class basic_istringstream
0105 : public basic_istream<charT, traits>
0106 {
0107 public:
0108 typedef charT char_type;
0109 typedef traits traits_type;
0110 typedef typename traits_type::int_type int_type;
0111 typedef typename traits_type::pos_type pos_type;
0112 typedef typename traits_type::off_type off_type;
0113 typedef Allocator allocator_type;
0114
0115 // [istringstream.cons] Constructors:
0116 explicit basic_istringstream(ios_base::openmode which = ios_base::in); // before C++20
0117 basic_istringstream() : basic_istringstream(ios_base::in) {} // C++20
0118 explicit basic_istringstream(ios_base::openmode which); // C++20
0119 explicit basic_istringstream(const basic_string<char_type, traits_type, allocator_type>& s,
0120 ios_base::openmode which = ios_base::in);
0121 basic_istringstream(ios_base::openmode which, const allocator_type& a); // C++20
0122 explicit basic_istringstream(basic_string<char_type, traits_type, allocator_type>&& s,
0123 ios_base::openmode which = ios_base::in); // C++20
0124 template <class SAlloc>
0125 basic_istringstream(const basic_string<char_type, traits_type, SAlloc>& s, const allocator_type& a)
0126 : basic_istringstream(s, ios_base::in, a) {} // C++20
0127 template <class SAlloc>
0128 basic_istringstream(const basic_string<char_type, traits_type, SAlloc>& s,
0129 ios_base::openmode which, const allocator_type& a); // C++20
0130 template <class SAlloc>
0131 explicit basic_istringstream(const basic_string<char_type, traits_type, SAlloc>& s,
0132 ios_base::openmode which = ios_base::in); // C++20
0133 template<class T>
0134 explicit basic_istringstream(const T& t, ios_base::openmode which = ios_base::in); // Since C++26
0135 template<class T>
0136 basic_istringstream(const T& t, const Allocator& a); // Since C++26
0137 template<class T>
0138 basic_istringstream(const T& t, ios_base::openmode which, const Allocator& a); // Since C++26
0139 basic_istringstream(const basic_istringstream&) = delete;
0140 basic_istringstream(basic_istringstream&& rhs);
0141
0142 // [istringstream.assign] Assign and swap:
0143 basic_istringstream& operator=(const basic_istringstream&) = delete;
0144 basic_istringstream& operator=(basic_istringstream&& rhs);
0145 void swap(basic_istringstream& rhs);
0146
0147 // [istringstream.members] Member functions:
0148 basic_stringbuf<char_type, traits_type, allocator_type>* rdbuf() const;
0149 basic_string<char_type, traits_type, allocator_type> str() const; // before C++20
0150 basic_string<char_type, traits_type, allocator_type> str() const &; // C++20
0151 template <class SAlloc>
0152 basic_string<char_type, traits_type, SAlloc> str(const SAlloc& sa) const; // C++20
0153 basic_string<char_type, traits_type, allocator_type> str() &&; // C++20
0154 basic_string_view<char_type, traits_type> view() const noexcept; // C++20
0155 void str(const basic_string<char_type, traits_type, allocator_type>& s);
0156 template <class SAlloc>
0157 void str(const basic_string<char_type, traits_type, SAlloc>& s); // C++20
0158 void str(basic_string<char_type, traits_type, allocator_type>&& s); // C++20
0159 template<class T>
0160 void str(const T& t); // Since C++26
0161 };
0162
0163 template <class charT, class traits, class Allocator>
0164 void swap(basic_istringstream<charT, traits, Allocator>& x,
0165 basic_istringstream<charT, traits, Allocator>& y);
0166
0167 typedef basic_istringstream<char> istringstream;
0168 typedef basic_istringstream<wchar_t> wistringstream;
0169
0170 // Class template basic_ostringstream [ostringstream]
0171 template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> >
0172 class basic_ostringstream
0173 : public basic_ostream<charT, traits>
0174 {
0175 public:
0176 // types:
0177 typedef charT char_type;
0178 typedef traits traits_type;
0179 typedef typename traits_type::int_type int_type;
0180 typedef typename traits_type::pos_type pos_type;
0181 typedef typename traits_type::off_type off_type;
0182 typedef Allocator allocator_type;
0183
0184 // [ostringstream.cons] Constructors:
0185 explicit basic_ostringstream(ios_base::openmode which = ios_base::out); // before C++20
0186 basic_ostringstream() : basic_ostringstream(ios_base::out) {} // C++20
0187 explicit basic_ostringstream(ios_base::openmode which); // C++20
0188 explicit basic_ostringstream(const basic_string<char_type, traits_type, allocator_type>& s,
0189 ios_base::openmode which = ios_base::out);
0190 basic_ostringstream(ios_base::openmode which, const allocator_type& a); // C++20
0191 explicit basic_ostringstream(basic_string<char_type, traits_type, allocator_type>&& s,
0192 ios_base::openmode which = ios_base::out); // C++20
0193 template <class SAlloc>
0194 basic_ostringstream(const basic_string<char_type, traits_type, SAlloc>& s, const allocator_type& a)
0195 : basic_ostringstream(s, ios_base::out, a) {} // C++20
0196 template <class SAlloc>
0197 basic_ostringstream(const basic_string<char_type, traits_type, SAlloc>& s,
0198 ios_base::openmode which, const allocator_type& a); // C++20
0199 template <class SAlloc>
0200 explicit basic_ostringstream(const basic_string<char_type, traits_type, SAlloc>& s,
0201 ios_base::openmode which = ios_base::out); // C++20
0202 template<class T>
0203 explicit basic_ostringstream(const T& t, ios_base::openmode which = ios_base::out); // Since C++26
0204 template<class T>
0205 basic_ostringstream(const T& t, const Allocator& a); // Since C++26
0206 template<class T>
0207 basic_ostringstream(const T& t, ios_base::openmode which, const Allocator& a); // Since C++26
0208 basic_ostringstream(const basic_ostringstream&) = delete;
0209 basic_ostringstream(basic_ostringstream&& rhs);
0210
0211 // [ostringstream.assign] Assign and swap:
0212 basic_ostringstream& operator=(const basic_ostringstream&) = delete;
0213 basic_ostringstream& operator=(basic_ostringstream&& rhs);
0214 void swap(basic_ostringstream& rhs);
0215
0216 // [ostringstream.members] Member functions:
0217 basic_stringbuf<char_type, traits_type, allocator_type>* rdbuf() const;
0218 basic_string<char_type, traits_type, allocator_type> str() const; // before C++20
0219 basic_string<char_type, traits_type, allocator_type> str() const &; // C++20
0220 template <class SAlloc>
0221 basic_string<char_type, traits_type, SAlloc> str(const SAlloc& sa) const; // C++20
0222 basic_string<char_type, traits_type, allocator_type> str() &&; // C++20
0223 basic_string_view<char_type, traits_type> view() const noexcept; // C++20
0224 void str(const basic_string<char_type, traits_type, allocator_type>& s);
0225 template <class SAlloc>
0226 void str(const basic_string<char_type, traits_type, SAlloc>& s); // C++20
0227 void str(basic_string<char_type, traits_type, allocator_type>&& s); // C++20
0228 template<class T>
0229 void str(const T& t); // Since C++26
0230 };
0231
0232 template <class charT, class traits, class Allocator>
0233 void swap(basic_ostringstream<charT, traits, Allocator>& x,
0234 basic_ostringstream<charT, traits, Allocator>& y);
0235
0236 typedef basic_ostringstream<char> ostringstream;
0237 typedef basic_ostringstream<wchar_t> wostringstream;
0238
0239 // Class template basic_stringstream [stringstream]
0240 template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> >
0241 class basic_stringstream
0242 : public basic_iostream<charT, traits>
0243 {
0244 public:
0245 // types:
0246 typedef charT char_type;
0247 typedef traits traits_type;
0248 typedef typename traits_type::int_type int_type;
0249 typedef typename traits_type::pos_type pos_type;
0250 typedef typename traits_type::off_type off_type;
0251 typedef Allocator allocator_type;
0252
0253 // [stringstream.cons] constructors
0254 explicit basic_stringstream(ios_base::openmode which = ios_base::out | ios_base::in); // before C++20
0255 basic_stringstream() : basic_stringstream(ios_base::out | ios_base::in) {} // C++20
0256 explicit basic_stringstream(ios_base::openmode which); // C++20
0257 explicit basic_stringstream(const basic_string<char_type, traits_type, allocator_type>& s,
0258 ios_base::openmode which = ios_base::out | ios_base::in);
0259 basic_stringstream(ios_base::openmode which, const allocator_type& a); // C++20
0260 explicit basic_stringstream(basic_string<char_type, traits_type, allocator_type>&& s,
0261 ios_base::openmode which = ios_base::out | ios_base::in); // C++20
0262 template <class SAlloc>
0263 basic_stringstream(const basic_string<char_type, traits_type, SAlloc>& s, const allocator_type& a)
0264 : basic_stringstream(s, ios_base::out | ios_base::in, a) {} // C++20
0265 template <class SAlloc>
0266 basic_stringstream(const basic_string<char_type, traits_type, SAlloc>& s,
0267 ios_base::openmode which, const allocator_type& a); // C++20
0268 template <class SAlloc>
0269 explicit basic_stringstream(const basic_string<char_type, traits_type, SAlloc>& s,
0270 ios_base::openmode which = ios_base::out | ios_base::in); // C++20
0271 template<class T>
0272 explicit basic_stringstream(const T& t,
0273 ios_base::openmode which = ios_base::out | ios_base::in); // Since C++26
0274 template<class T>
0275 basic_stringstream(const T& t, const Allocator& a); // Since C++26
0276 template<class T>
0277 basic_stringstream(const T& t, ios_base::openmode which, const Allocator& a); // Since C++26
0278 basic_stringstream(const basic_stringstream&) = delete;
0279 basic_stringstream(basic_stringstream&& rhs);
0280
0281 // [stringstream.assign] Assign and swap:
0282 basic_stringstream& operator=(const basic_stringstream&) = delete;
0283 basic_stringstream& operator=(basic_stringstream&& rhs);
0284 void swap(basic_stringstream& rhs);
0285
0286 // [stringstream.members] Member functions:
0287 basic_stringbuf<char_type, traits_type, allocator_type>* rdbuf() const;
0288 basic_string<char_type, traits_type, allocator_type> str() const; // before C++20
0289 basic_string<char_type, traits_type, allocator_type> str() const &; // C++20
0290 template <class SAlloc>
0291 basic_string<char_type, traits_type, SAlloc> str(const SAlloc& sa) const; // C++20
0292 basic_string<char_type, traits_type, allocator_type> str() &&; // C++20
0293 basic_string_view<char_type, traits_type> view() const noexcept; // C++20
0294 void str(const basic_string<char_type, traits_type, allocator_type>& s);
0295 template <class SAlloc>
0296 void str(const basic_string<char_type, traits_type, SAlloc>& s); // C++20
0297 void str(basic_string<char_type, traits_type, allocator_type>&& s); // C++20
0298 template<class T>
0299 void str(const T& t); // Since C++26
0300 };
0301
0302 template <class charT, class traits, class Allocator>
0303 void swap(basic_stringstream<charT, traits, Allocator>& x,
0304 basic_stringstream<charT, traits, Allocator>& y);
0305
0306 typedef basic_stringstream<char> stringstream;
0307 typedef basic_stringstream<wchar_t> wstringstream;
0308
0309 } // std
0310
0311 */
0312
0313 // clang-format on
0314
0315 #if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
0316 # include <__cxx03/sstream>
0317 #else
0318 # include <__config>
0319
0320 # if _LIBCPP_HAS_LOCALIZATION
0321
0322 # include <__fwd/sstream.h>
0323 # include <__ostream/basic_ostream.h>
0324 # include <__type_traits/is_convertible.h>
0325 # include <__utility/swap.h>
0326 # include <ios>
0327 # include <istream>
0328 # include <locale>
0329 # include <string>
0330 # include <string_view>
0331 # include <version>
0332
0333 # if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0334 # pragma GCC system_header
0335 # endif
0336
0337 _LIBCPP_PUSH_MACROS
0338 # include <__undef_macros>
0339
0340 _LIBCPP_BEGIN_NAMESPACE_STD
0341
0342 // Class template basic_stringbuf [stringbuf]
0343
0344 template <class _CharT, class _Traits, class _Allocator>
0345 class _LIBCPP_TEMPLATE_VIS basic_stringbuf : public basic_streambuf<_CharT, _Traits> {
0346 public:
0347 typedef _CharT char_type;
0348 typedef _Traits traits_type;
0349 typedef typename traits_type::int_type int_type;
0350 typedef typename traits_type::pos_type pos_type;
0351 typedef typename traits_type::off_type off_type;
0352 typedef _Allocator allocator_type;
0353
0354 typedef basic_string<char_type, traits_type, allocator_type> string_type;
0355
0356 private:
0357 string_type __str_;
0358 mutable char_type* __hm_;
0359 ios_base::openmode __mode_;
0360 _LIBCPP_HIDE_FROM_ABI void __init_buf_ptrs();
0361 _LIBCPP_HIDE_FROM_ABI void __move_init(basic_stringbuf&& __rhs);
0362
0363 public:
0364 // [stringbuf.cons] constructors:
0365 _LIBCPP_HIDE_FROM_ABI basic_stringbuf() : __hm_(nullptr), __mode_(ios_base::in | ios_base::out) {
0366 // it is implementation-defined whether we initialize eback() & friends to nullptr, and libc++ doesn't
0367 __init_buf_ptrs();
0368 }
0369
0370 _LIBCPP_HIDE_FROM_ABI explicit basic_stringbuf(ios_base::openmode __wch) : __hm_(nullptr), __mode_(__wch) {
0371 // it is implementation-defined whether we initialize eback() & friends to nullptr, and libc++ doesn't
0372 __init_buf_ptrs();
0373 }
0374
0375 _LIBCPP_HIDE_FROM_ABI explicit basic_stringbuf(const string_type& __s,
0376 ios_base::openmode __wch = ios_base::in | ios_base::out)
0377 : __str_(__s.get_allocator()), __hm_(nullptr), __mode_(__wch) {
0378 str(__s);
0379 }
0380
0381 # if _LIBCPP_STD_VER >= 20
0382 _LIBCPP_HIDE_FROM_ABI explicit basic_stringbuf(const allocator_type& __a)
0383 : basic_stringbuf(ios_base::in | ios_base::out, __a) {}
0384
0385 _LIBCPP_HIDE_FROM_ABI basic_stringbuf(ios_base::openmode __wch, const allocator_type& __a)
0386 : __str_(__a), __hm_(nullptr), __mode_(__wch) {
0387 __init_buf_ptrs();
0388 }
0389
0390 _LIBCPP_HIDE_FROM_ABI explicit basic_stringbuf(string_type&& __s,
0391 ios_base::openmode __wch = ios_base::in | ios_base::out)
0392 : __str_(std::move(__s)), __hm_(nullptr), __mode_(__wch) {
0393 __init_buf_ptrs();
0394 }
0395
0396 template <class _SAlloc>
0397 _LIBCPP_HIDE_FROM_ABI
0398 basic_stringbuf(const basic_string<char_type, traits_type, _SAlloc>& __s, const allocator_type& __a)
0399 : basic_stringbuf(__s, ios_base::in | ios_base::out, __a) {}
0400
0401 template <class _SAlloc>
0402 _LIBCPP_HIDE_FROM_ABI basic_stringbuf(
0403 const basic_string<char_type, traits_type, _SAlloc>& __s, ios_base::openmode __wch, const allocator_type& __a)
0404 : __str_(__s, __a), __hm_(nullptr), __mode_(__wch) {
0405 __init_buf_ptrs();
0406 }
0407
0408 template <class _SAlloc>
0409 requires(!is_same_v<_SAlloc, allocator_type>)
0410 _LIBCPP_HIDE_FROM_ABI explicit basic_stringbuf(const basic_string<char_type, traits_type, _SAlloc>& __s,
0411 ios_base::openmode __wch = ios_base::in | ios_base::out)
0412 : __str_(__s), __hm_(nullptr), __mode_(__wch) {
0413 __init_buf_ptrs();
0414 }
0415 # endif // _LIBCPP_STD_VER >= 20
0416
0417 # if _LIBCPP_STD_VER >= 26
0418
0419 template <class _Tp>
0420 requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>>
0421 _LIBCPP_HIDE_FROM_ABI explicit basic_stringbuf(const _Tp& __t,
0422 ios_base::openmode __which = ios_base::in | ios_base::out)
0423 : basic_stringbuf(__t, __which, _Allocator()) {}
0424
0425 template <class _Tp>
0426 requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>>
0427 _LIBCPP_HIDE_FROM_ABI basic_stringbuf(const _Tp& __t, const _Allocator& __a)
0428 : basic_stringbuf(__t, ios_base::in | ios_base::out, __a) {}
0429
0430 template <class _Tp>
0431 requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>>
0432 _LIBCPP_HIDE_FROM_ABI basic_stringbuf(const _Tp& __t, ios_base::openmode __which, const _Allocator& __a)
0433 : __hm_(nullptr), __mode_(__which) {
0434 basic_string_view<_CharT, _Traits> __sv = __t;
0435 __str_ = string_type(__sv, __a);
0436 __init_buf_ptrs();
0437 }
0438
0439 # endif // _LIBCPP_STD_VER >= 26
0440
0441 basic_stringbuf(const basic_stringbuf&) = delete;
0442 basic_stringbuf(basic_stringbuf&& __rhs) : __mode_(__rhs.__mode_) { __move_init(std::move(__rhs)); }
0443
0444 # if _LIBCPP_STD_VER >= 20
0445 _LIBCPP_HIDE_FROM_ABI basic_stringbuf(basic_stringbuf&& __rhs, const allocator_type& __a)
0446 : basic_stringbuf(__rhs.__mode_, __a) {
0447 __move_init(std::move(__rhs));
0448 }
0449 # endif
0450
0451 // [stringbuf.assign] Assign and swap:
0452 basic_stringbuf& operator=(const basic_stringbuf&) = delete;
0453 basic_stringbuf& operator=(basic_stringbuf&& __rhs);
0454 void swap(basic_stringbuf& __rhs)
0455 # if _LIBCPP_STD_VER >= 20
0456 noexcept(allocator_traits<allocator_type>::propagate_on_container_swap::value ||
0457 allocator_traits<allocator_type>::is_always_equal::value)
0458 # endif
0459 ;
0460
0461 // [stringbuf.members] Member functions:
0462
0463 # if _LIBCPP_STD_VER >= 20
0464 _LIBCPP_HIDE_FROM_ABI allocator_type get_allocator() const noexcept { return __str_.get_allocator(); }
0465 # endif
0466
0467 # if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_BUILDING_LIBRARY)
0468 string_type str() const;
0469 # else
0470 _LIBCPP_HIDE_FROM_ABI string_type str() const& { return str(__str_.get_allocator()); }
0471
0472 _LIBCPP_HIDE_FROM_ABI string_type str() && {
0473 const basic_string_view<_CharT, _Traits> __view = view();
0474 typename string_type::size_type __pos = __view.empty() ? 0 : __view.data() - __str_.data();
0475 // In C++23, this is just string_type(std::move(__str_), __pos, __view.size(), __str_.get_allocator());
0476 // But we need something that works in C++20 also.
0477 string_type __result(std::move(__str_), __str_.get_allocator());
0478 __result.resize(__pos + __view.size());
0479 __result.erase(0, __pos);
0480 __init_buf_ptrs();
0481 return __result;
0482 }
0483 # endif // _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_BUILDING_LIBRARY)
0484
0485 # if _LIBCPP_STD_VER >= 20
0486 template <class _SAlloc>
0487 requires __is_allocator<_SAlloc>::value
0488 _LIBCPP_HIDE_FROM_ABI basic_string<char_type, traits_type, _SAlloc> str(const _SAlloc& __sa) const {
0489 return basic_string<_CharT, _Traits, _SAlloc>(view(), __sa);
0490 }
0491
0492 _LIBCPP_HIDE_FROM_ABI basic_string_view<char_type, traits_type> view() const noexcept;
0493 # endif // _LIBCPP_STD_VER >= 20
0494
0495 void str(const string_type& __s) {
0496 __str_ = __s;
0497 __init_buf_ptrs();
0498 }
0499
0500 # if _LIBCPP_STD_VER >= 20
0501 template <class _SAlloc>
0502 requires(!is_same_v<_SAlloc, allocator_type>)
0503 _LIBCPP_HIDE_FROM_ABI void str(const basic_string<char_type, traits_type, _SAlloc>& __s) {
0504 __str_ = __s;
0505 __init_buf_ptrs();
0506 }
0507
0508 _LIBCPP_HIDE_FROM_ABI void str(string_type&& __s) {
0509 __str_ = std::move(__s);
0510 __init_buf_ptrs();
0511 }
0512 # endif // _LIBCPP_STD_VER >= 20
0513
0514 # if _LIBCPP_STD_VER >= 26
0515
0516 template <class _Tp>
0517 requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>>
0518 _LIBCPP_HIDE_FROM_ABI void str(const _Tp& __t) {
0519 basic_string_view<_CharT, _Traits> __sv = __t;
0520 __str_ = __sv;
0521 __init_buf_ptrs();
0522 }
0523
0524 # endif // _LIBCPP_STD_VER >= 26
0525
0526 protected:
0527 // [stringbuf.virtuals] Overridden virtual functions:
0528 int_type underflow() override;
0529 int_type pbackfail(int_type __c = traits_type::eof()) override;
0530 int_type overflow(int_type __c = traits_type::eof()) override;
0531 pos_type
0532 seekoff(off_type __off, ios_base::seekdir __way, ios_base::openmode __wch = ios_base::in | ios_base::out) override;
0533 _LIBCPP_HIDE_FROM_ABI_VIRTUAL
0534 pos_type seekpos(pos_type __sp, ios_base::openmode __wch = ios_base::in | ios_base::out) override {
0535 return seekoff(__sp, ios_base::beg, __wch);
0536 }
0537 };
0538
0539 template <class _CharT, class _Traits, class _Allocator>
0540 _LIBCPP_HIDE_FROM_ABI void basic_stringbuf<_CharT, _Traits, _Allocator>::__move_init(basic_stringbuf&& __rhs) {
0541 char_type* __p = const_cast<char_type*>(__rhs.__str_.data());
0542 ptrdiff_t __binp = -1;
0543 ptrdiff_t __ninp = -1;
0544 ptrdiff_t __einp = -1;
0545 if (__rhs.eback() != nullptr) {
0546 __binp = __rhs.eback() - __p;
0547 __ninp = __rhs.gptr() - __p;
0548 __einp = __rhs.egptr() - __p;
0549 }
0550 ptrdiff_t __bout = -1;
0551 ptrdiff_t __nout = -1;
0552 ptrdiff_t __eout = -1;
0553 if (__rhs.pbase() != nullptr) {
0554 __bout = __rhs.pbase() - __p;
0555 __nout = __rhs.pptr() - __p;
0556 __eout = __rhs.epptr() - __p;
0557 }
0558 ptrdiff_t __hm = __rhs.__hm_ == nullptr ? -1 : __rhs.__hm_ - __p;
0559 __str_ = std::move(__rhs.__str_);
0560 __p = const_cast<char_type*>(__str_.data());
0561 if (__binp != -1)
0562 this->setg(__p + __binp, __p + __ninp, __p + __einp);
0563 if (__bout != -1) {
0564 this->setp(__p + __bout, __p + __eout);
0565 this->__pbump(__nout);
0566 }
0567 __hm_ = __hm == -1 ? nullptr : __p + __hm;
0568 __p = const_cast<char_type*>(__rhs.__str_.data());
0569 __rhs.setg(__p, __p, __p);
0570 __rhs.setp(__p, __p);
0571 __rhs.__hm_ = __p;
0572 this->pubimbue(__rhs.getloc());
0573 }
0574
0575 template <class _CharT, class _Traits, class _Allocator>
0576 basic_stringbuf<_CharT, _Traits, _Allocator>&
0577 basic_stringbuf<_CharT, _Traits, _Allocator>::operator=(basic_stringbuf&& __rhs) {
0578 char_type* __p = const_cast<char_type*>(__rhs.__str_.data());
0579 ptrdiff_t __binp = -1;
0580 ptrdiff_t __ninp = -1;
0581 ptrdiff_t __einp = -1;
0582 if (__rhs.eback() != nullptr) {
0583 __binp = __rhs.eback() - __p;
0584 __ninp = __rhs.gptr() - __p;
0585 __einp = __rhs.egptr() - __p;
0586 }
0587 ptrdiff_t __bout = -1;
0588 ptrdiff_t __nout = -1;
0589 ptrdiff_t __eout = -1;
0590 if (__rhs.pbase() != nullptr) {
0591 __bout = __rhs.pbase() - __p;
0592 __nout = __rhs.pptr() - __p;
0593 __eout = __rhs.epptr() - __p;
0594 }
0595 ptrdiff_t __hm = __rhs.__hm_ == nullptr ? -1 : __rhs.__hm_ - __p;
0596 __str_ = std::move(__rhs.__str_);
0597 __p = const_cast<char_type*>(__str_.data());
0598 if (__binp != -1)
0599 this->setg(__p + __binp, __p + __ninp, __p + __einp);
0600 else
0601 this->setg(nullptr, nullptr, nullptr);
0602 if (__bout != -1) {
0603 this->setp(__p + __bout, __p + __eout);
0604 this->__pbump(__nout);
0605 } else
0606 this->setp(nullptr, nullptr);
0607
0608 __hm_ = __hm == -1 ? nullptr : __p + __hm;
0609 __mode_ = __rhs.__mode_;
0610 __p = const_cast<char_type*>(__rhs.__str_.data());
0611 __rhs.setg(__p, __p, __p);
0612 __rhs.setp(__p, __p);
0613 __rhs.__hm_ = __p;
0614 this->pubimbue(__rhs.getloc());
0615 return *this;
0616 }
0617
0618 template <class _CharT, class _Traits, class _Allocator>
0619 void basic_stringbuf<_CharT, _Traits, _Allocator>::swap(basic_stringbuf& __rhs)
0620 # if _LIBCPP_STD_VER >= 20
0621 noexcept(allocator_traits<_Allocator>::propagate_on_container_swap::value ||
0622 allocator_traits<_Allocator>::is_always_equal::value)
0623 # endif
0624 {
0625 char_type* __p = const_cast<char_type*>(__rhs.__str_.data());
0626 ptrdiff_t __rbinp = -1;
0627 ptrdiff_t __rninp = -1;
0628 ptrdiff_t __reinp = -1;
0629 if (__rhs.eback() != nullptr) {
0630 __rbinp = __rhs.eback() - __p;
0631 __rninp = __rhs.gptr() - __p;
0632 __reinp = __rhs.egptr() - __p;
0633 }
0634 ptrdiff_t __rbout = -1;
0635 ptrdiff_t __rnout = -1;
0636 ptrdiff_t __reout = -1;
0637 if (__rhs.pbase() != nullptr) {
0638 __rbout = __rhs.pbase() - __p;
0639 __rnout = __rhs.pptr() - __p;
0640 __reout = __rhs.epptr() - __p;
0641 }
0642 ptrdiff_t __rhm = __rhs.__hm_ == nullptr ? -1 : __rhs.__hm_ - __p;
0643 __p = const_cast<char_type*>(__str_.data());
0644 ptrdiff_t __lbinp = -1;
0645 ptrdiff_t __lninp = -1;
0646 ptrdiff_t __leinp = -1;
0647 if (this->eback() != nullptr) {
0648 __lbinp = this->eback() - __p;
0649 __lninp = this->gptr() - __p;
0650 __leinp = this->egptr() - __p;
0651 }
0652 ptrdiff_t __lbout = -1;
0653 ptrdiff_t __lnout = -1;
0654 ptrdiff_t __leout = -1;
0655 if (this->pbase() != nullptr) {
0656 __lbout = this->pbase() - __p;
0657 __lnout = this->pptr() - __p;
0658 __leout = this->epptr() - __p;
0659 }
0660 ptrdiff_t __lhm = __hm_ == nullptr ? -1 : __hm_ - __p;
0661 std::swap(__mode_, __rhs.__mode_);
0662 __str_.swap(__rhs.__str_);
0663 __p = const_cast<char_type*>(__str_.data());
0664 if (__rbinp != -1)
0665 this->setg(__p + __rbinp, __p + __rninp, __p + __reinp);
0666 else
0667 this->setg(nullptr, nullptr, nullptr);
0668 if (__rbout != -1) {
0669 this->setp(__p + __rbout, __p + __reout);
0670 this->__pbump(__rnout);
0671 } else
0672 this->setp(nullptr, nullptr);
0673 __hm_ = __rhm == -1 ? nullptr : __p + __rhm;
0674 __p = const_cast<char_type*>(__rhs.__str_.data());
0675 if (__lbinp != -1)
0676 __rhs.setg(__p + __lbinp, __p + __lninp, __p + __leinp);
0677 else
0678 __rhs.setg(nullptr, nullptr, nullptr);
0679 if (__lbout != -1) {
0680 __rhs.setp(__p + __lbout, __p + __leout);
0681 __rhs.__pbump(__lnout);
0682 } else
0683 __rhs.setp(nullptr, nullptr);
0684 __rhs.__hm_ = __lhm == -1 ? nullptr : __p + __lhm;
0685 locale __tl = __rhs.getloc();
0686 __rhs.pubimbue(this->getloc());
0687 this->pubimbue(__tl);
0688 }
0689
0690 template <class _CharT, class _Traits, class _Allocator>
0691 inline _LIBCPP_HIDE_FROM_ABI void
0692 swap(basic_stringbuf<_CharT, _Traits, _Allocator>& __x, basic_stringbuf<_CharT, _Traits, _Allocator>& __y)
0693 # if _LIBCPP_STD_VER >= 20
0694 noexcept(noexcept(__x.swap(__y)))
0695 # endif
0696 {
0697 __x.swap(__y);
0698 }
0699
0700 # if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_BUILDING_LIBRARY)
0701 template <class _CharT, class _Traits, class _Allocator>
0702 basic_string<_CharT, _Traits, _Allocator> basic_stringbuf<_CharT, _Traits, _Allocator>::str() const {
0703 if (__mode_ & ios_base::out) {
0704 if (__hm_ < this->pptr())
0705 __hm_ = this->pptr();
0706 return string_type(this->pbase(), __hm_, __str_.get_allocator());
0707 } else if (__mode_ & ios_base::in)
0708 return string_type(this->eback(), this->egptr(), __str_.get_allocator());
0709 return string_type(__str_.get_allocator());
0710 }
0711 # endif // _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_BUILDING_LIBRARY)
0712
0713 template <class _CharT, class _Traits, class _Allocator>
0714 _LIBCPP_HIDE_FROM_ABI void basic_stringbuf<_CharT, _Traits, _Allocator>::__init_buf_ptrs() {
0715 __hm_ = nullptr;
0716 char_type* __data = const_cast<char_type*>(__str_.data());
0717 typename string_type::size_type __sz = __str_.size();
0718 if (__mode_ & ios_base::in) {
0719 __hm_ = __data + __sz;
0720 this->setg(__data, __data, __hm_);
0721 }
0722 if (__mode_ & ios_base::out) {
0723 __hm_ = __data + __sz;
0724 __str_.resize(__str_.capacity());
0725 this->setp(__data, __data + __str_.size());
0726 if (__mode_ & (ios_base::app | ios_base::ate)) {
0727 while (__sz > INT_MAX) {
0728 this->pbump(INT_MAX);
0729 __sz -= INT_MAX;
0730 }
0731 if (__sz > 0)
0732 this->pbump(__sz);
0733 }
0734 }
0735 }
0736
0737 # if _LIBCPP_STD_VER >= 20
0738 template <class _CharT, class _Traits, class _Allocator>
0739 _LIBCPP_HIDE_FROM_ABI basic_string_view<_CharT, _Traits>
0740 basic_stringbuf<_CharT, _Traits, _Allocator>::view() const noexcept {
0741 if (__mode_ & ios_base::out) {
0742 if (__hm_ < this->pptr())
0743 __hm_ = this->pptr();
0744 return basic_string_view<_CharT, _Traits>(this->pbase(), __hm_);
0745 } else if (__mode_ & ios_base::in)
0746 return basic_string_view<_CharT, _Traits>(this->eback(), this->egptr());
0747 return basic_string_view<_CharT, _Traits>();
0748 }
0749 # endif // _LIBCPP_STD_VER >= 20
0750
0751 template <class _CharT, class _Traits, class _Allocator>
0752 typename basic_stringbuf<_CharT, _Traits, _Allocator>::int_type
0753 basic_stringbuf<_CharT, _Traits, _Allocator>::underflow() {
0754 if (__hm_ < this->pptr())
0755 __hm_ = this->pptr();
0756 if (__mode_ & ios_base::in) {
0757 if (this->egptr() < __hm_)
0758 this->setg(this->eback(), this->gptr(), __hm_);
0759 if (this->gptr() < this->egptr())
0760 return traits_type::to_int_type(*this->gptr());
0761 }
0762 return traits_type::eof();
0763 }
0764
0765 template <class _CharT, class _Traits, class _Allocator>
0766 typename basic_stringbuf<_CharT, _Traits, _Allocator>::int_type
0767 basic_stringbuf<_CharT, _Traits, _Allocator>::pbackfail(int_type __c) {
0768 if (__hm_ < this->pptr())
0769 __hm_ = this->pptr();
0770 if (this->eback() < this->gptr()) {
0771 if (traits_type::eq_int_type(__c, traits_type::eof())) {
0772 this->setg(this->eback(), this->gptr() - 1, __hm_);
0773 return traits_type::not_eof(__c);
0774 }
0775 if ((__mode_ & ios_base::out) || traits_type::eq(traits_type::to_char_type(__c), this->gptr()[-1])) {
0776 this->setg(this->eback(), this->gptr() - 1, __hm_);
0777 *this->gptr() = traits_type::to_char_type(__c);
0778 return __c;
0779 }
0780 }
0781 return traits_type::eof();
0782 }
0783
0784 template <class _CharT, class _Traits, class _Allocator>
0785 typename basic_stringbuf<_CharT, _Traits, _Allocator>::int_type
0786 basic_stringbuf<_CharT, _Traits, _Allocator>::overflow(int_type __c) {
0787 if (!traits_type::eq_int_type(__c, traits_type::eof())) {
0788 ptrdiff_t __ninp = this->gptr() - this->eback();
0789 if (this->pptr() == this->epptr()) {
0790 if (!(__mode_ & ios_base::out))
0791 return traits_type::eof();
0792 # if _LIBCPP_HAS_EXCEPTIONS
0793 try {
0794 # endif // _LIBCPP_HAS_EXCEPTIONS
0795 ptrdiff_t __nout = this->pptr() - this->pbase();
0796 ptrdiff_t __hm = __hm_ - this->pbase();
0797 __str_.push_back(char_type());
0798 __str_.resize(__str_.capacity());
0799 char_type* __p = const_cast<char_type*>(__str_.data());
0800 this->setp(__p, __p + __str_.size());
0801 this->__pbump(__nout);
0802 __hm_ = this->pbase() + __hm;
0803 # if _LIBCPP_HAS_EXCEPTIONS
0804 } catch (...) {
0805 return traits_type::eof();
0806 }
0807 # endif // _LIBCPP_HAS_EXCEPTIONS
0808 }
0809 __hm_ = std::max(this->pptr() + 1, __hm_);
0810 if (__mode_ & ios_base::in) {
0811 char_type* __p = const_cast<char_type*>(__str_.data());
0812 this->setg(__p, __p + __ninp, __hm_);
0813 }
0814 return this->sputc(traits_type::to_char_type(__c));
0815 }
0816 return traits_type::not_eof(__c);
0817 }
0818
0819 template <class _CharT, class _Traits, class _Allocator>
0820 typename basic_stringbuf<_CharT, _Traits, _Allocator>::pos_type basic_stringbuf<_CharT, _Traits, _Allocator>::seekoff(
0821 off_type __off, ios_base::seekdir __way, ios_base::openmode __wch) {
0822 if (__hm_ < this->pptr())
0823 __hm_ = this->pptr();
0824 if ((__wch & (ios_base::in | ios_base::out)) == 0)
0825 return pos_type(-1);
0826 if ((__wch & (ios_base::in | ios_base::out)) == (ios_base::in | ios_base::out) && __way == ios_base::cur)
0827 return pos_type(-1);
0828 const ptrdiff_t __hm = __hm_ == nullptr ? 0 : __hm_ - __str_.data();
0829 off_type __noff;
0830 switch (__way) {
0831 case ios_base::beg:
0832 __noff = 0;
0833 break;
0834 case ios_base::cur:
0835 if (__wch & ios_base::in)
0836 __noff = this->gptr() - this->eback();
0837 else
0838 __noff = this->pptr() - this->pbase();
0839 break;
0840 case ios_base::end:
0841 __noff = __hm;
0842 break;
0843 default:
0844 return pos_type(-1);
0845 }
0846 __noff += __off;
0847 if (__noff < 0 || __hm < __noff)
0848 return pos_type(-1);
0849 if (__noff != 0) {
0850 if ((__wch & ios_base::in) && this->gptr() == nullptr)
0851 return pos_type(-1);
0852 if ((__wch & ios_base::out) && this->pptr() == nullptr)
0853 return pos_type(-1);
0854 }
0855 if (__wch & ios_base::in)
0856 this->setg(this->eback(), this->eback() + __noff, __hm_);
0857 if (__wch & ios_base::out) {
0858 this->setp(this->pbase(), this->epptr());
0859 this->__pbump(__noff);
0860 }
0861 return pos_type(__noff);
0862 }
0863
0864 // Class template basic_istringstream [istringstream]
0865
0866 template <class _CharT, class _Traits, class _Allocator>
0867 class _LIBCPP_TEMPLATE_VIS basic_istringstream : public basic_istream<_CharT, _Traits> {
0868 public:
0869 typedef _CharT char_type;
0870 typedef _Traits traits_type;
0871 typedef typename traits_type::int_type int_type;
0872 typedef typename traits_type::pos_type pos_type;
0873 typedef typename traits_type::off_type off_type;
0874 typedef _Allocator allocator_type;
0875
0876 typedef basic_string<char_type, traits_type, allocator_type> string_type;
0877
0878 private:
0879 basic_stringbuf<char_type, traits_type, allocator_type> __sb_;
0880
0881 public:
0882 // [istringstream.cons] Constructors:
0883 _LIBCPP_HIDE_FROM_ABI basic_istringstream()
0884 : basic_istream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(ios_base::in) {}
0885
0886 _LIBCPP_HIDE_FROM_ABI explicit basic_istringstream(ios_base::openmode __wch)
0887 : basic_istream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__wch | ios_base::in) {}
0888
0889 _LIBCPP_HIDE_FROM_ABI explicit basic_istringstream(const string_type& __s, ios_base::openmode __wch = ios_base::in)
0890 : basic_istream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__s, __wch | ios_base::in) {}
0891
0892 # if _LIBCPP_STD_VER >= 20
0893 _LIBCPP_HIDE_FROM_ABI basic_istringstream(ios_base::openmode __wch, const _Allocator& __a)
0894 : basic_istream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__wch | ios_base::in, __a) {}
0895
0896 _LIBCPP_HIDE_FROM_ABI explicit basic_istringstream(string_type&& __s, ios_base::openmode __wch = ios_base::in)
0897 : basic_istream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(std::move(__s), __wch | ios_base::in) {}
0898
0899 template <class _SAlloc>
0900 _LIBCPP_HIDE_FROM_ABI basic_istringstream(const basic_string<_CharT, _Traits, _SAlloc>& __s, const _Allocator& __a)
0901 : basic_istringstream(__s, ios_base::in, __a) {}
0902
0903 template <class _SAlloc>
0904 _LIBCPP_HIDE_FROM_ABI basic_istringstream(
0905 const basic_string<_CharT, _Traits, _SAlloc>& __s, ios_base::openmode __wch, const _Allocator& __a)
0906 : basic_istream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__s, __wch | ios_base::in, __a) {}
0907
0908 template <class _SAlloc>
0909 _LIBCPP_HIDE_FROM_ABI explicit basic_istringstream(const basic_string<_CharT, _Traits, _SAlloc>& __s,
0910 ios_base::openmode __wch = ios_base::in)
0911 : basic_istream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__s, __wch | ios_base::in) {}
0912 # endif // _LIBCPP_STD_VER >= 20
0913
0914 # if _LIBCPP_STD_VER >= 26
0915
0916 template <class _Tp>
0917 requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>>
0918 _LIBCPP_HIDE_FROM_ABI explicit basic_istringstream(const _Tp& __t, ios_base::openmode __which = ios_base::in)
0919 : basic_istringstream(__t, __which, _Allocator()) {}
0920
0921 template <class _Tp>
0922 requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>>
0923 _LIBCPP_HIDE_FROM_ABI basic_istringstream(const _Tp& __t, const _Allocator& __a)
0924 : basic_istringstream(__t, ios_base::in, __a) {}
0925
0926 template <class _Tp>
0927 requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>>
0928 _LIBCPP_HIDE_FROM_ABI basic_istringstream(const _Tp& __t, ios_base::openmode __which, const _Allocator& __a)
0929 : basic_istream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__t, __which | ios_base::in, __a) {}
0930
0931 # endif // _LIBCPP_STD_VER >= 26
0932
0933 basic_istringstream(const basic_istringstream&) = delete;
0934 _LIBCPP_HIDE_FROM_ABI basic_istringstream(basic_istringstream&& __rhs)
0935 : basic_istream<_CharT, _Traits>(std::move(__rhs)), __sb_(std::move(__rhs.__sb_)) {
0936 basic_istream<_CharT, _Traits>::set_rdbuf(std::addressof(__sb_));
0937 }
0938
0939 // [istringstream.assign] Assign and swap:
0940 basic_istringstream& operator=(const basic_istringstream&) = delete;
0941 basic_istringstream& operator=(basic_istringstream&& __rhs) {
0942 basic_istream<char_type, traits_type>::operator=(std::move(__rhs));
0943 __sb_ = std::move(__rhs.__sb_);
0944 return *this;
0945 }
0946 _LIBCPP_HIDE_FROM_ABI void swap(basic_istringstream& __rhs) {
0947 basic_istream<char_type, traits_type>::swap(__rhs);
0948 __sb_.swap(__rhs.__sb_);
0949 }
0950
0951 // [istringstream.members] Member functions:
0952 _LIBCPP_HIDE_FROM_ABI basic_stringbuf<char_type, traits_type, allocator_type>* rdbuf() const {
0953 return const_cast<basic_stringbuf<char_type, traits_type, allocator_type>*>(std::addressof(__sb_));
0954 }
0955
0956 # if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_BUILDING_LIBRARY)
0957 _LIBCPP_HIDE_FROM_ABI string_type str() const { return __sb_.str(); }
0958 # else
0959 _LIBCPP_HIDE_FROM_ABI string_type str() const& { return __sb_.str(); }
0960
0961 _LIBCPP_HIDE_FROM_ABI string_type str() && { return std::move(__sb_).str(); }
0962 # endif
0963
0964 # if _LIBCPP_STD_VER >= 20
0965 template <class _SAlloc>
0966 requires __is_allocator<_SAlloc>::value
0967 _LIBCPP_HIDE_FROM_ABI basic_string<char_type, traits_type, _SAlloc> str(const _SAlloc& __sa) const {
0968 return __sb_.str(__sa);
0969 }
0970
0971 _LIBCPP_HIDE_FROM_ABI basic_string_view<char_type, traits_type> view() const noexcept { return __sb_.view(); }
0972 # endif // _LIBCPP_STD_VER >= 20
0973
0974 _LIBCPP_HIDE_FROM_ABI void str(const string_type& __s) { __sb_.str(__s); }
0975
0976 # if _LIBCPP_STD_VER >= 20
0977 template <class _SAlloc>
0978 _LIBCPP_HIDE_FROM_ABI void str(const basic_string<char_type, traits_type, _SAlloc>& __s) {
0979 __sb_.str(__s);
0980 }
0981
0982 _LIBCPP_HIDE_FROM_ABI void str(string_type&& __s) { __sb_.str(std::move(__s)); }
0983 # endif // _LIBCPP_STD_VER >= 20
0984
0985 # if _LIBCPP_STD_VER >= 26
0986 template <class _Tp>
0987 requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>>
0988 _LIBCPP_HIDE_FROM_ABI void str(const _Tp& __t) {
0989 rdbuf()->str(__t);
0990 }
0991 # endif // _LIBCPP_STD_VER >= 26
0992 };
0993
0994 template <class _CharT, class _Traits, class _Allocator>
0995 inline _LIBCPP_HIDE_FROM_ABI void
0996 swap(basic_istringstream<_CharT, _Traits, _Allocator>& __x, basic_istringstream<_CharT, _Traits, _Allocator>& __y) {
0997 __x.swap(__y);
0998 }
0999
1000 // Class template basic_ostringstream [ostringstream]
1001
1002 template <class _CharT, class _Traits, class _Allocator>
1003 class _LIBCPP_TEMPLATE_VIS basic_ostringstream : public basic_ostream<_CharT, _Traits> {
1004 public:
1005 typedef _CharT char_type;
1006 typedef _Traits traits_type;
1007 typedef typename traits_type::int_type int_type;
1008 typedef typename traits_type::pos_type pos_type;
1009 typedef typename traits_type::off_type off_type;
1010 typedef _Allocator allocator_type;
1011
1012 typedef basic_string<char_type, traits_type, allocator_type> string_type;
1013
1014 private:
1015 basic_stringbuf<char_type, traits_type, allocator_type> __sb_;
1016
1017 public:
1018 // [ostringstream.cons] Constructors:
1019 _LIBCPP_HIDE_FROM_ABI basic_ostringstream()
1020 : basic_ostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(ios_base::out) {}
1021
1022 _LIBCPP_HIDE_FROM_ABI explicit basic_ostringstream(ios_base::openmode __wch)
1023 : basic_ostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__wch | ios_base::out) {}
1024
1025 _LIBCPP_HIDE_FROM_ABI explicit basic_ostringstream(const string_type& __s, ios_base::openmode __wch = ios_base::out)
1026 : basic_ostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__s, __wch | ios_base::out) {}
1027
1028 # if _LIBCPP_STD_VER >= 20
1029 _LIBCPP_HIDE_FROM_ABI basic_ostringstream(ios_base::openmode __wch, const _Allocator& __a)
1030 : basic_ostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__wch | ios_base::out, __a) {}
1031
1032 _LIBCPP_HIDE_FROM_ABI explicit basic_ostringstream(string_type&& __s, ios_base::openmode __wch = ios_base::out)
1033 : basic_ostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(std::move(__s), __wch | ios_base::out) {}
1034
1035 template <class _SAlloc>
1036 _LIBCPP_HIDE_FROM_ABI basic_ostringstream(const basic_string<_CharT, _Traits, _SAlloc>& __s, const _Allocator& __a)
1037 : basic_ostringstream(__s, ios_base::out, __a) {}
1038
1039 template <class _SAlloc>
1040 _LIBCPP_HIDE_FROM_ABI basic_ostringstream(
1041 const basic_string<_CharT, _Traits, _SAlloc>& __s, ios_base::openmode __wch, const _Allocator& __a)
1042 : basic_ostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__s, __wch | ios_base::out, __a) {}
1043
1044 template <class _SAlloc>
1045 requires(!is_same_v<_SAlloc, allocator_type>)
1046 _LIBCPP_HIDE_FROM_ABI explicit basic_ostringstream(const basic_string<_CharT, _Traits, _SAlloc>& __s,
1047 ios_base::openmode __wch = ios_base::out)
1048 : basic_ostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__s, __wch | ios_base::out) {}
1049 # endif // _LIBCPP_STD_VER >= 20
1050
1051 # if _LIBCPP_STD_VER >= 26
1052
1053 template <class _Tp>
1054 requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>>
1055 _LIBCPP_HIDE_FROM_ABI explicit basic_ostringstream(const _Tp& __t, ios_base::openmode __which = ios_base::out)
1056 : basic_ostringstream(__t, __which | ios_base::out, _Allocator()) {}
1057
1058 template <class _Tp>
1059 requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>>
1060 _LIBCPP_HIDE_FROM_ABI basic_ostringstream(const _Tp& __t, const _Allocator& __a)
1061 : basic_ostringstream(__t, ios_base::out, __a) {}
1062
1063 template <class _Tp>
1064 requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>>
1065 _LIBCPP_HIDE_FROM_ABI basic_ostringstream(const _Tp& __t, ios_base::openmode __which, const _Allocator& __a)
1066 : basic_ostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__t, __which | ios_base::out, __a) {}
1067
1068 # endif // _LIBCPP_STD_VER >= 26
1069
1070 basic_ostringstream(const basic_ostringstream&) = delete;
1071 _LIBCPP_HIDE_FROM_ABI basic_ostringstream(basic_ostringstream&& __rhs)
1072 : basic_ostream<_CharT, _Traits>(std::move(__rhs)), __sb_(std::move(__rhs.__sb_)) {
1073 basic_ostream<_CharT, _Traits>::set_rdbuf(std::addressof(__sb_));
1074 }
1075
1076 // [ostringstream.assign] Assign and swap:
1077 basic_ostringstream& operator=(const basic_ostringstream&) = delete;
1078 basic_ostringstream& operator=(basic_ostringstream&& __rhs) {
1079 basic_ostream<char_type, traits_type>::operator=(std::move(__rhs));
1080 __sb_ = std::move(__rhs.__sb_);
1081 return *this;
1082 }
1083
1084 _LIBCPP_HIDE_FROM_ABI void swap(basic_ostringstream& __rhs) {
1085 basic_ostream<char_type, traits_type>::swap(__rhs);
1086 __sb_.swap(__rhs.__sb_);
1087 }
1088
1089 // [ostringstream.members] Member functions:
1090 _LIBCPP_HIDE_FROM_ABI basic_stringbuf<char_type, traits_type, allocator_type>* rdbuf() const {
1091 return const_cast<basic_stringbuf<char_type, traits_type, allocator_type>*>(std::addressof(__sb_));
1092 }
1093
1094 # if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_BUILDING_LIBRARY)
1095 _LIBCPP_HIDE_FROM_ABI string_type str() const { return __sb_.str(); }
1096 # else
1097 _LIBCPP_HIDE_FROM_ABI string_type str() const& { return __sb_.str(); }
1098
1099 _LIBCPP_HIDE_FROM_ABI string_type str() && { return std::move(__sb_).str(); }
1100 # endif
1101
1102 # if _LIBCPP_STD_VER >= 20
1103 template <class _SAlloc>
1104 requires __is_allocator<_SAlloc>::value
1105 _LIBCPP_HIDE_FROM_ABI basic_string<char_type, traits_type, _SAlloc> str(const _SAlloc& __sa) const {
1106 return __sb_.str(__sa);
1107 }
1108
1109 _LIBCPP_HIDE_FROM_ABI basic_string_view<char_type, traits_type> view() const noexcept { return __sb_.view(); }
1110 # endif // _LIBCPP_STD_VER >= 20
1111
1112 _LIBCPP_HIDE_FROM_ABI void str(const string_type& __s) { __sb_.str(__s); }
1113
1114 # if _LIBCPP_STD_VER >= 20
1115 template <class _SAlloc>
1116 _LIBCPP_HIDE_FROM_ABI void str(const basic_string<char_type, traits_type, _SAlloc>& __s) {
1117 __sb_.str(__s);
1118 }
1119
1120 _LIBCPP_HIDE_FROM_ABI void str(string_type&& __s) { __sb_.str(std::move(__s)); }
1121 # endif // _LIBCPP_STD_VER >= 20
1122
1123 # if _LIBCPP_STD_VER >= 26
1124 template <class _Tp>
1125 requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>>
1126 _LIBCPP_HIDE_FROM_ABI void str(const _Tp& __t) {
1127 rdbuf()->str(__t);
1128 }
1129 # endif // _LIBCPP_STD_VER >= 26
1130 };
1131
1132 template <class _CharT, class _Traits, class _Allocator>
1133 inline _LIBCPP_HIDE_FROM_ABI void
1134 swap(basic_ostringstream<_CharT, _Traits, _Allocator>& __x, basic_ostringstream<_CharT, _Traits, _Allocator>& __y) {
1135 __x.swap(__y);
1136 }
1137
1138 // Class template basic_stringstream [stringstream]
1139
1140 template <class _CharT, class _Traits, class _Allocator>
1141 class _LIBCPP_TEMPLATE_VIS basic_stringstream : public basic_iostream<_CharT, _Traits> {
1142 public:
1143 typedef _CharT char_type;
1144 typedef _Traits traits_type;
1145 typedef typename traits_type::int_type int_type;
1146 typedef typename traits_type::pos_type pos_type;
1147 typedef typename traits_type::off_type off_type;
1148 typedef _Allocator allocator_type;
1149
1150 typedef basic_string<char_type, traits_type, allocator_type> string_type;
1151
1152 private:
1153 basic_stringbuf<char_type, traits_type, allocator_type> __sb_;
1154
1155 public:
1156 // [stringstream.cons] constructors
1157 _LIBCPP_HIDE_FROM_ABI basic_stringstream()
1158 : basic_iostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(ios_base::in | ios_base::out) {}
1159
1160 _LIBCPP_HIDE_FROM_ABI explicit basic_stringstream(ios_base::openmode __wch)
1161 : basic_iostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__wch) {}
1162
1163 _LIBCPP_HIDE_FROM_ABI explicit basic_stringstream(const string_type& __s,
1164 ios_base::openmode __wch = ios_base::in | ios_base::out)
1165 : basic_iostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__s, __wch) {}
1166
1167 # if _LIBCPP_STD_VER >= 20
1168 _LIBCPP_HIDE_FROM_ABI basic_stringstream(ios_base::openmode __wch, const _Allocator& __a)
1169 : basic_iostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__wch, __a) {}
1170
1171 _LIBCPP_HIDE_FROM_ABI explicit basic_stringstream(string_type&& __s,
1172 ios_base::openmode __wch = ios_base::out | ios_base::in)
1173 : basic_iostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(std::move(__s), __wch) {}
1174
1175 template <class _SAlloc>
1176 _LIBCPP_HIDE_FROM_ABI basic_stringstream(const basic_string<_CharT, _Traits, _SAlloc>& __s, const _Allocator& __a)
1177 : basic_stringstream(__s, ios_base::out | ios_base::in, __a) {}
1178
1179 template <class _SAlloc>
1180 _LIBCPP_HIDE_FROM_ABI
1181 basic_stringstream(const basic_string<_CharT, _Traits, _SAlloc>& __s, ios_base::openmode __wch, const _Allocator& __a)
1182 : basic_iostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__s, __wch, __a) {}
1183
1184 template <class _SAlloc>
1185 requires(!is_same_v<_SAlloc, allocator_type>)
1186 _LIBCPP_HIDE_FROM_ABI explicit basic_stringstream(const basic_string<_CharT, _Traits, _SAlloc>& __s,
1187 ios_base::openmode __wch = ios_base::out | ios_base::in)
1188 : basic_iostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__s, __wch) {}
1189 # endif // _LIBCPP_STD_VER >= 20
1190
1191 # if _LIBCPP_STD_VER >= 26
1192
1193 template <class _Tp>
1194 requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>>
1195 _LIBCPP_HIDE_FROM_ABI explicit basic_stringstream(const _Tp& __t,
1196 ios_base::openmode __which = ios_base::out | ios_base::in)
1197 : basic_stringstream(__t, __which, _Allocator()) {}
1198
1199 template <class _Tp>
1200 requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>>
1201 _LIBCPP_HIDE_FROM_ABI basic_stringstream(const _Tp& __t, const _Allocator& __a)
1202 : basic_stringstream(__t, ios_base::out | ios_base::in, __a) {}
1203
1204 template <class _Tp>
1205 requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>>
1206 _LIBCPP_HIDE_FROM_ABI basic_stringstream(const _Tp& __t, ios_base::openmode __which, const _Allocator& __a)
1207 : basic_iostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__t, __which, __a) {}
1208
1209 # endif // _LIBCPP_STD_VER >= 26
1210
1211 basic_stringstream(const basic_stringstream&) = delete;
1212 _LIBCPP_HIDE_FROM_ABI basic_stringstream(basic_stringstream&& __rhs)
1213 : basic_iostream<_CharT, _Traits>(std::move(__rhs)), __sb_(std::move(__rhs.__sb_)) {
1214 basic_istream<_CharT, _Traits>::set_rdbuf(std::addressof(__sb_));
1215 }
1216
1217 // [stringstream.assign] Assign and swap:
1218 basic_stringstream& operator=(const basic_stringstream&) = delete;
1219 basic_stringstream& operator=(basic_stringstream&& __rhs) {
1220 basic_iostream<char_type, traits_type>::operator=(std::move(__rhs));
1221 __sb_ = std::move(__rhs.__sb_);
1222 return *this;
1223 }
1224 _LIBCPP_HIDE_FROM_ABI void swap(basic_stringstream& __rhs) {
1225 basic_iostream<char_type, traits_type>::swap(__rhs);
1226 __sb_.swap(__rhs.__sb_);
1227 }
1228
1229 // [stringstream.members] Member functions:
1230 _LIBCPP_HIDE_FROM_ABI basic_stringbuf<char_type, traits_type, allocator_type>* rdbuf() const {
1231 return const_cast<basic_stringbuf<char_type, traits_type, allocator_type>*>(std::addressof(__sb_));
1232 }
1233
1234 # if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_BUILDING_LIBRARY)
1235 _LIBCPP_HIDE_FROM_ABI string_type str() const { return __sb_.str(); }
1236 # else
1237 _LIBCPP_HIDE_FROM_ABI string_type str() const& { return __sb_.str(); }
1238
1239 _LIBCPP_HIDE_FROM_ABI string_type str() && { return std::move(__sb_).str(); }
1240 # endif
1241
1242 # if _LIBCPP_STD_VER >= 20
1243 template <class _SAlloc>
1244 requires __is_allocator<_SAlloc>::value
1245 _LIBCPP_HIDE_FROM_ABI basic_string<char_type, traits_type, _SAlloc> str(const _SAlloc& __sa) const {
1246 return __sb_.str(__sa);
1247 }
1248
1249 _LIBCPP_HIDE_FROM_ABI basic_string_view<char_type, traits_type> view() const noexcept { return __sb_.view(); }
1250 # endif // _LIBCPP_STD_VER >= 20
1251
1252 _LIBCPP_HIDE_FROM_ABI void str(const string_type& __s) { __sb_.str(__s); }
1253
1254 # if _LIBCPP_STD_VER >= 20
1255 template <class _SAlloc>
1256 _LIBCPP_HIDE_FROM_ABI void str(const basic_string<char_type, traits_type, _SAlloc>& __s) {
1257 __sb_.str(__s);
1258 }
1259
1260 _LIBCPP_HIDE_FROM_ABI void str(string_type&& __s) { __sb_.str(std::move(__s)); }
1261 # endif // _LIBCPP_STD_VER >= 20
1262
1263 # if _LIBCPP_STD_VER >= 26
1264 template <class _Tp>
1265 requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>>
1266 _LIBCPP_HIDE_FROM_ABI void str(const _Tp& __t) {
1267 rdbuf()->str(__t);
1268 }
1269 # endif // _LIBCPP_STD_VER >= 26
1270 };
1271
1272 template <class _CharT, class _Traits, class _Allocator>
1273 inline _LIBCPP_HIDE_FROM_ABI void
1274 swap(basic_stringstream<_CharT, _Traits, _Allocator>& __x, basic_stringstream<_CharT, _Traits, _Allocator>& __y) {
1275 __x.swap(__y);
1276 }
1277
1278 # if _LIBCPP_AVAILABILITY_HAS_ADDITIONAL_IOSTREAM_EXPLICIT_INSTANTIATIONS_1
1279 extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_stringbuf<char>;
1280 extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_stringstream<char>;
1281 extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ostringstream<char>;
1282 extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_istringstream<char>;
1283 # endif
1284
1285 _LIBCPP_END_NAMESPACE_STD
1286
1287 _LIBCPP_POP_MACROS
1288
1289 # endif // _LIBCPP_HAS_LOCALIZATION
1290
1291 # if _LIBCPP_STD_VER <= 20 && !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES)
1292 # include <ostream>
1293 # include <type_traits>
1294 # endif
1295 #endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
1296
1297 #endif // _LIBCPP_SSTREAM