diff --git a/libcxx/docs/ReleaseNotes.rst b/libcxx/docs/ReleaseNotes.rst --- a/libcxx/docs/ReleaseNotes.rst +++ b/libcxx/docs/ReleaseNotes.rst @@ -47,6 +47,7 @@ - P2505R5 - Monadic operations for ``std::expected`` - P2711R1 - Making Multi-Param Constructors Of views explicit (``join_with_view`` is not done yet) - P2572R1 - ``std::format`` fill character allowances +- P0408R7 - Efficient Access to ``basic_stringbuf``'s Buffer Improvements and New Features ----------------------------- diff --git a/libcxx/docs/Status/Cxx20.rst b/libcxx/docs/Status/Cxx20.rst --- a/libcxx/docs/Status/Cxx20.rst +++ b/libcxx/docs/Status/Cxx20.rst @@ -49,7 +49,6 @@ .. [#note-P0883.1] P0883: shared_ptr and floating-point changes weren't applied as they themselves aren't implemented yet. .. [#note-P0883.2] P0883: ``ATOMIC_FLAG_INIT`` was marked deprecated in version 14.0, but was undeprecated with the implementation of LWG3659 in version 15.0. .. [#note-P2231] P2231: Optional is complete. The changes to variant haven't been implemented yet. - .. [#note-P0408] P0408: Only `view()` members implemented. .. [#note-P0660] P0660: Section 32.3 Stop Tokens is complete. ``jthread`` hasn't been implemented yet. .. _issues-status-cxx20: diff --git a/libcxx/docs/Status/Cxx20Papers.csv b/libcxx/docs/Status/Cxx20Papers.csv --- a/libcxx/docs/Status/Cxx20Papers.csv +++ b/libcxx/docs/Status/Cxx20Papers.csv @@ -99,7 +99,7 @@ "`P1464R1 `__","LWG","Mandating the Standard Library: Clause 22 - Iterators library","Kona","|Complete|","9.0" "","","","","","","" "`P0325R4 `__","LWG","to_array from LFTS with updates","Cologne","|Complete|","10.0" -"`P0408R7 `__","LWG","Efficient Access to basic_stringbuf's Buffer","Cologne","|In Progress| [#note-P0408]_","" +"`P0408R7 `__","LWG","Efficient Access to basic_stringbuf's Buffer","Cologne","|Complete|","17.0" "`P0466R5 `__","LWG","Layout-compatibility and Pointer-interconvertibility Traits","Cologne","","" "`P0553R4 `__","LWG","Bit operations","Cologne","|Complete|","9.0" "`P0631R8 `__","LWG","Math Constants","Cologne","|Complete|","11.0" diff --git a/libcxx/include/sstream b/libcxx/include/sstream --- a/libcxx/include/sstream +++ b/libcxx/include/sstream @@ -30,18 +30,41 @@ explicit basic_stringbuf(ios_base::openmode which = ios_base::in | ios_base::out); // before C++20 basic_stringbuf() : basic_stringbuf(ios_base::in | ios_base::out) {} // C++20 explicit basic_stringbuf(ios_base::openmode which); // C++20 - explicit basic_stringbuf(const basic_string& str, + explicit basic_stringbuf(const basic_string& s, ios_base::openmode which = ios_base::in | ios_base::out); + explicit basic_stringbuf(const allocator_type& a) + : basic_stringbuf(ios_base::in | ios_base::out, a) {} // C++20 + basic_stringbuf(ios_base::openmode which, const allocator_type& a); // C++20 + explicit basic_stringbuf(const basic_string&& s, + ios_base::openmode which = ios_base::in | ios_base::out); // C++20 + template + basic_stringbuf(const basic_string& s, const allocator_type& a) + : basic_stringbuf(s, ios_base::in | ios_base::out, a) {} // C++20 + template + basic_stringbuf(const basic_string& s, + ios_base::openmode which, const allocator_type& a); // C++20 + template + explicit basic_stringbuf(const basic_string& s, + ios_base::openmode which = ios_base::in | ios_base::out); // C++20 basic_stringbuf(basic_stringbuf&& rhs); + basic_stringbuf(basic_stringbuf&& rhs, const allocator_type& a); // C++20 // [stringbuf.assign] Assign and swap: basic_stringbuf& operator=(basic_stringbuf&& rhs); void swap(basic_stringbuf& rhs); // [stringbuf.members] Member functions: - basic_string str() const; + allocator_type get_allocator() const noexcept; // C++20 + basic_string str() const; // before C++20 + basic_string str() const &; // C++20 void str(const basic_string& s); - basic_string_view view() const noexcept; // C++20 + template + basic_string str(const SAlloc& sa) const; // C++20 + basic_string str() &&; // C++20 + template + void str(const basic_string& s); // C++20 + void str(basic_string&& s); // C++20 + basic_string_view view() const noexcept; // C++20 protected: // [stringbuf.virtuals] Overridden virtual functions: @@ -77,12 +100,23 @@ typedef Allocator allocator_type; // [istringstream.cons] Constructors: - explicit basic_istringstream(ios_base::openmode which = ios_base::in); // before C++20 - basic_istringstream() : basic_istringstream(ios_base::in) {} // C++20 - explicit basic_istringstream(ios_base::openmode which); // C++20 - - explicit basic_istringstream(const basic_string& str, + explicit basic_istringstream(ios_base::openmode which = ios_base::in); // before C++20 + basic_istringstream() : basic_istringstream(ios_base::in) {} // C++20 + explicit basic_istringstream(ios_base::openmode which); // C++20 + explicit basic_istringstream(const basic_string& s, ios_base::openmode which = ios_base::in); + basic_istringstream(ios_base::openmode which, const allocator_type& a); // C++20 + explicit basic_istringstream(basic_string&& s, + ios_base::openmode which = ios_base::in); // C++20 + template + basic_istringstream(const basic_string& s, const allocator_type& a) + : basic_istringstream(s, ios_base::in, a) {} // C++20 + template + basic_istringstream(const basic_string& s, + ios_base::openmode which, const allocator_type& a); // C++20 + template + explicit basic_istringstream(const basic_string& s, + ios_base::openmode which = ios_base::in); // C++20 basic_istringstream(basic_istringstream&& rhs); // [istringstream.assign] Assign and swap: @@ -91,9 +125,16 @@ // [istringstream.members] Member functions: basic_stringbuf* rdbuf() const; - basic_string str() const; + basic_string str() const; // before C++20 + basic_string str() const &; // C++20 + basic_string str() &&; // C++20 void str(const basic_string& s); - basic_string_view view() const noexcept; // C++20 + template + basic_string str(const SAlloc& sa) const; // C++20 + template + void str(const basic_string& s); // C++20 + void str(basic_string&& s); // C++20 + basic_string_view view() const noexcept; // C++20 }; template @@ -118,12 +159,23 @@ typedef Allocator allocator_type; // [ostringstream.cons] Constructors: - explicit basic_ostringstream(ios_base::openmode which = ios_base::out); // before C++20 - basic_ostringstream() : basic_ostringstream(ios_base::out) {} // C++20 - explicit basic_ostringstream(ios_base::openmode which); // C++20 - - explicit basic_ostringstream(const basic_string& str, + explicit basic_ostringstream(ios_base::openmode which = ios_base::out); // before C++20 + basic_ostringstream() : basic_ostringstream(ios_base::out) {} // C++20 + explicit basic_ostringstream(ios_base::openmode which); // C++20 + explicit basic_ostringstream(const basic_string& s, ios_base::openmode which = ios_base::out); + basic_ostringstream(ios_base::openmode which, const allocator_type& a); // C++20 + explicit basic_ostringstream(basic_string&& s, + ios_base::openmode which = ios_base::out); // C++20 + template + basic_ostringstream(const basic_string& s, const allocator_type& a) + : basic_ostringstream(s, ios_base::out, a) {} // C++20 + template + basic_ostringstream(const basic_string& s, + ios_base::openmode which, const allocator_type& a); // C++20 + template + explicit basic_ostringstream(const basic_string& s, + ios_base::openmode which = ios_base::out); // C++20 basic_ostringstream(basic_ostringstream&& rhs); // [ostringstream.assign] Assign and swap: @@ -132,9 +184,16 @@ // [ostringstream.members] Member functions: basic_stringbuf* rdbuf() const; - basic_string str() const; + basic_string str() const; // before C++20 + basic_string str() const &; // C++20 + basic_string str() &&; // C++20 void str(const basic_string& s); - basic_string_view view() const noexcept; // C++20 + template + basic_string str(const SAlloc& sa) const; // C++20 + template + void str(const basic_string& s); // C++20 + void str(basic_string&& s); // C++20 + basic_string_view view() const noexcept; // C++20 }; template @@ -159,12 +218,23 @@ typedef Allocator allocator_type; // [stringstream.cons] constructors - explicit basic_stringstream(ios_base::openmode which = ios_base::out | ios_base::in); // before C++20 - basic_stringstream() : basic_stringstream(ios_base::out | ios_base::in) {} // C++20 + explicit basic_stringstream(ios_base::openmode which = ios_base::in | ios_base::out); // before C++20 + basic_stringstream() : basic_stringstream(ios_base::in | ios_base::out) {} // C++20 explicit basic_stringstream(ios_base::openmode which); // C++20 - - explicit basic_stringstream(const basic_string& str, - ios_base::openmode which = ios_base::out|ios_base::in); + explicit basic_stringstream(const basic_string& s, + ios_base::openmode which = ios_base::in | ios_base::out); + basic_stringstream(ios_base::openmode which, const allocator_type& a); // C++20 + explicit basic_stringstream(basic_string&& s, + ios_base::openmode which = ios_base::in | ios_base::out); // C++20 + template + basic_stringstream(const basic_string& s, const allocator_type& a) + : basic_stringstream(s, ios_base::in | ios_base::out, a) {} // C++20 + template + basic_stringstream(const basic_string& s, + ios_base::openmode which, const allocator_type& a); // C++20 + template + explicit basic_stringstream(const basic_string& s, + ios_base::openmode which = ios_base::in | ios_base::out); // C++20 basic_stringstream(basic_stringstream&& rhs); // [stringstream.assign] Assign and swap: @@ -173,9 +243,16 @@ // [stringstream.members] Member functions: basic_stringbuf* rdbuf() const; - basic_string str() const; - void str(const basic_string& str); - basic_string_view view() const noexcept; // C++20 + basic_string str() const; // before C++20 + basic_string str() const &; // C++20 + basic_string str() &&; // C++20 + void str(const basic_string& s); + template + basic_string str(const SAlloc& sa) const; // C++20 + template + void str(const basic_string& s); // C++20 + void str(basic_string&& s); // C++20 + basic_string_view view() const noexcept; // C++20 }; template @@ -229,6 +306,8 @@ string_type __str_; mutable char_type* __hm_; ios_base::openmode __mode_; + _LIBCPP_HIDE_FROM_ABI void __init_buf_ptrs(); + _LIBCPP_HIDE_FROM_ABI void __move_init(basic_stringbuf&& __rhs); public: // [stringbuf.cons] constructors: @@ -248,20 +327,98 @@ str(__s); } - basic_stringbuf(basic_stringbuf&& __rhs); + basic_stringbuf(basic_stringbuf&& __rhs) : __mode_(__rhs.__mode_) { __move_init(std::move(__rhs)); } + +#if _LIBCPP_STD_VER >= 20 + _LIBCPP_HIDE_FROM_ABI explicit basic_stringbuf(const allocator_type& __a) + : basic_stringbuf(ios_base::in | ios_base::out, __a) {} + + _LIBCPP_HIDE_FROM_ABI basic_stringbuf(ios_base::openmode __wch, const allocator_type& __a) + : __str_(__a), __hm_(nullptr), __mode_(__wch) {} + + _LIBCPP_HIDE_FROM_ABI explicit basic_stringbuf(string_type&& __s, + ios_base::openmode __wch = ios_base::in | ios_base::out) + : __str_(std::move(__s)), __hm_(nullptr), __mode_(__wch) { + __init_buf_ptrs(); + } + + template + _LIBCPP_HIDE_FROM_ABI + basic_stringbuf(const basic_string& __s, const allocator_type& __a) + : basic_stringbuf(__s, ios_base::in | ios_base::out, __a) {} + + template + _LIBCPP_HIDE_FROM_ABI basic_stringbuf( + const basic_string& __s, ios_base::openmode __wch, const allocator_type& __a) + : __str_(__s, __a), __hm_(nullptr), __mode_(__wch) { + __init_buf_ptrs(); + } + + template + _LIBCPP_HIDE_FROM_ABI explicit basic_stringbuf(const basic_string& __s, + ios_base::openmode __wch = ios_base::in | ios_base::out) + : __str_(__s), __hm_(nullptr), __mode_(__wch) { + __init_buf_ptrs(); + } + + _LIBCPP_HIDE_FROM_ABI basic_stringbuf(basic_stringbuf&& __rhs, const allocator_type& __a) + : basic_stringbuf(__rhs.__mode_, __a) { + __move_init(std::move(__rhs)); + } +#endif // _LIBCPP_STD_VER >= 20 // [stringbuf.assign] Assign and swap: basic_stringbuf& operator=(basic_stringbuf&& __rhs); - void swap(basic_stringbuf& __rhs); + void swap(basic_stringbuf& __rhs) +#if _LIBCPP_STD_VER >= 20 + noexcept(allocator_traits::propagate_on_container_swap::value || + allocator_traits::is_always_equal::value) +#endif + ; // [stringbuf.members] Member functions: + +#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_BUILDING_LIBRARY) string_type str() const; - void str(const string_type& __s); -#if _LIBCPP_STD_VER >= 20 - _LIBCPP_HIDE_FROM_ABI - basic_string_view view() const noexcept; +#else + _LIBCPP_HIDE_FROM_ABI string_type str() const & { return str(__str_.get_allocator()); } + _LIBCPP_HIDE_FROM_ABI string_type str() && { + const basic_string_view<_CharT, _Traits> __view = view(); + string_type __result(std::move(__str_), __view.data() - __str_.data(), __view.size()); + __str_.clear(); + __init_buf_ptrs(); + return __result; + } #endif + void str(const string_type& __s) { + __str_ = __s; + __init_buf_ptrs(); + } + +#if _LIBCPP_STD_VER >= 20 + _LIBCPP_HIDE_FROM_ABI allocator_type get_allocator() const noexcept { return __str_.get_allocator(); } + + template + requires __is_allocator<_SAlloc>::value + _LIBCPP_HIDE_FROM_ABI basic_string str(const _SAlloc& __sa) const { + return basic_string<_CharT, _Traits, _SAlloc>(view(), __sa); + } + + template + _LIBCPP_HIDE_FROM_ABI void str(const basic_string& __s) { + __str_ = __s; + __init_buf_ptrs(); + } + + _LIBCPP_HIDE_FROM_ABI void str(string_type&& __s) { + __str_ = std::move(__s); + __init_buf_ptrs(); + } + + _LIBCPP_HIDE_FROM_ABI basic_string_view view() const noexcept; +#endif // _LIBCPP_STD_VER >= 20 + protected: // [stringbuf.virtuals] Overridden virtual functions: int_type underflow() override; @@ -277,9 +434,7 @@ }; template -basic_stringbuf<_CharT, _Traits, _Allocator>::basic_stringbuf(basic_stringbuf&& __rhs) - : __mode_(__rhs.__mode_) -{ +_LIBCPP_HIDE_FROM_ABI void basic_stringbuf<_CharT, _Traits, _Allocator>::__move_init(basic_stringbuf&& __rhs) { char_type* __p = const_cast(__rhs.__str_.data()); ptrdiff_t __binp = -1; ptrdiff_t __ninp = -1; @@ -366,8 +521,11 @@ } template -void -basic_stringbuf<_CharT, _Traits, _Allocator>::swap(basic_stringbuf& __rhs) +void basic_stringbuf<_CharT, _Traits, _Allocator>::swap(basic_stringbuf& __rhs) +#if _LIBCPP_STD_VER >= 20 + noexcept(allocator_traits<_Allocator>::propagate_on_container_swap::value || + allocator_traits<_Allocator>::is_always_equal::value) +#endif { char_type* __p = const_cast(__rhs.__str_.data()); ptrdiff_t __rbinp = -1; @@ -443,57 +601,44 @@ } template -inline _LIBCPP_INLINE_VISIBILITY -void -swap(basic_stringbuf<_CharT, _Traits, _Allocator>& __x, - basic_stringbuf<_CharT, _Traits, _Allocator>& __y) +inline _LIBCPP_INLINE_VISIBILITY void +swap(basic_stringbuf<_CharT, _Traits, _Allocator>& __x, basic_stringbuf<_CharT, _Traits, _Allocator>& __y) +#if _LIBCPP_STD_VER >= 20 + noexcept(noexcept(__x.swap(__y))) +#endif { __x.swap(__y); } +#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_BUILDING_LIBRARY) template basic_string<_CharT, _Traits, _Allocator> -basic_stringbuf<_CharT, _Traits, _Allocator>::str() const -{ -#if _LIBCPP_STD_VER >= 20 - return string_type(view(), __str_.get_allocator()); -#else // _LIBCPP_STD_VER >= 20 - if (__mode_ & ios_base::out) - { +basic_stringbuf<_CharT, _Traits, _Allocator>::str() const { + if (__mode_ & ios_base::out) { if (__hm_ < this->pptr()) __hm_ = this->pptr(); return string_type(this->pbase(), __hm_, __str_.get_allocator()); - } - else if (__mode_ & ios_base::in) + } else if (__mode_ & ios_base::in) return string_type(this->eback(), this->egptr(), __str_.get_allocator()); return string_type(__str_.get_allocator()); -#endif // _LIBCPP_STD_VER >= 20 } +#endif // _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_BUILDING_LIBRARY) template -void -basic_stringbuf<_CharT, _Traits, _Allocator>::str(const string_type& __s) -{ - __str_ = __s; +_LIBCPP_HIDE_FROM_ABI void basic_stringbuf<_CharT, _Traits, _Allocator>::__init_buf_ptrs() { __hm_ = nullptr; - if (__mode_ & ios_base::in) - { - __hm_ = const_cast(__str_.data()) + __str_.size(); - this->setg(const_cast(__str_.data()), - const_cast(__str_.data()), - __hm_); + char_type* __data = const_cast(__str_.data()); + typename string_type::size_type __sz = __str_.size(); + if (__mode_ & ios_base::in) { + __hm_ = __data + __sz; + this->setg(__data, __data, __hm_); } - if (__mode_ & ios_base::out) - { - typename string_type::size_type __sz = __str_.size(); - __hm_ = const_cast(__str_.data()) + __sz; + if (__mode_ & ios_base::out) { + __hm_ = __data + __sz; __str_.resize(__str_.capacity()); - this->setp(const_cast(__str_.data()), - const_cast(__str_.data()) + __str_.size()); - if (__mode_ & (ios_base::app | ios_base::ate)) - { - while (__sz > INT_MAX) - { + this->setp(__data, __data + __str_.size()); + if (__mode_ & (ios_base::app | ios_base::ate)) { + while (__sz > INT_MAX) { this->pbump(INT_MAX); __sz -= INT_MAX; } @@ -687,6 +832,28 @@ , __sb_(__s, __wch | ios_base::in) { } +#if _LIBCPP_STD_VER >= 20 + _LIBCPP_HIDE_FROM_ABI basic_istringstream(ios_base::openmode __wch, const _Allocator& __a) + : basic_istream<_CharT, _Traits>(&__sb_), __sb_(__wch | ios_base::in, __a) {} + + _LIBCPP_HIDE_FROM_ABI explicit basic_istringstream(string_type&& __s, ios_base::openmode __wch = ios_base::in) + : basic_istream<_CharT, _Traits>(&__sb_), __sb_(std::move(__s), __wch | ios_base::in) {} + + template + _LIBCPP_HIDE_FROM_ABI basic_istringstream(const basic_string<_CharT, _Traits, _SAlloc>& __s, const _Allocator& __a) + : basic_istringstream(__s, ios_base::in, __a) {} + + template + _LIBCPP_HIDE_FROM_ABI basic_istringstream( + const basic_string<_CharT, _Traits, _SAlloc>& __s, ios_base::openmode __wch, const _Allocator& __a) + : basic_istream<_CharT, _Traits>(&__sb_), __sb_(__s, __wch | ios_base::in, __a) {} + + template + _LIBCPP_HIDE_FROM_ABI explicit basic_istringstream(const basic_string<_CharT, _Traits, _SAlloc>& __s, + ios_base::openmode __wch = ios_base::in) + : basic_istream<_CharT, _Traits>(&__sb_), __sb_(__s, __wch | ios_base::in) {} +#endif // _LIBCPP_STD_VER >= 20 + _LIBCPP_INLINE_VISIBILITY basic_istringstream(basic_istringstream&& __rhs) : basic_istream<_CharT, _Traits>(_VSTD::move(__rhs)) @@ -713,19 +880,32 @@ return const_cast*>(&__sb_); } _LIBCPP_INLINE_VISIBILITY - string_type str() const { - return __sb_.str(); - } - _LIBCPP_INLINE_VISIBILITY void str(const string_type& __s) { __sb_.str(__s); } + #if _LIBCPP_STD_VER >= 20 - _LIBCPP_HIDE_FROM_ABI - basic_string_view view() const noexcept { - return __sb_.view(); + _LIBCPP_HIDE_FROM_ABI string_type str() const & { return __sb_.str(); } + + template + requires __is_allocator<_SAlloc>::value + _LIBCPP_HIDE_FROM_ABI basic_string str(const _SAlloc& __sa) const { + return __sb_.str(__sa); } -#endif + + _LIBCPP_HIDE_FROM_ABI string_type str() && { return std::move(__sb_).str(); } + + template + _LIBCPP_HIDE_FROM_ABI void str(const basic_string& __s) { + __sb_.str(__s); + } + + _LIBCPP_HIDE_FROM_ABI void str(string_type&& __s) { __sb_.str(std::move(__s)); } + + _LIBCPP_HIDE_FROM_ABI basic_string_view view() const noexcept { return __sb_.view(); } +#else // _LIBCPP_STD_VER >= 20 + _LIBCPP_HIDE_FROM_ABI string_type str() const { return __sb_.str(); } +#endif // _LIBCPP_STD_VER >= 20 }; template @@ -773,6 +953,28 @@ , __sb_(__s, __wch | ios_base::out) { } +#if _LIBCPP_STD_VER >= 20 + _LIBCPP_HIDE_FROM_ABI basic_ostringstream(ios_base::openmode __wch, const _Allocator& __a) + : basic_ostream<_CharT, _Traits>(&__sb_), __sb_(__wch | ios_base::out, __a) {} + + _LIBCPP_HIDE_FROM_ABI explicit basic_ostringstream(string_type&& __s, ios_base::openmode __wch = ios_base::out) + : basic_ostream<_CharT, _Traits>(&__sb_), __sb_(std::move(__s), __wch | ios_base::out) {} + + template + _LIBCPP_HIDE_FROM_ABI basic_ostringstream(const basic_string<_CharT, _Traits, _SAlloc>& __s, const _Allocator& __a) + : basic_ostream<_CharT, _Traits>(&__sb_), __sb_(__s, ios_base::out, __a) {} + + template + _LIBCPP_HIDE_FROM_ABI basic_ostringstream( + const basic_string<_CharT, _Traits, _SAlloc>& __s, ios_base::openmode __wch, const _Allocator& __a) + : basic_ostream<_CharT, _Traits>(&__sb_), __sb_(__s, __wch | ios_base::out, __a) {} + + template + _LIBCPP_HIDE_FROM_ABI explicit basic_ostringstream(const basic_string<_CharT, _Traits, _SAlloc>& __s, + ios_base::openmode __wch = ios_base::out) + : basic_ostream<_CharT, _Traits>(&__sb_), __sb_(__s, __wch | ios_base::out) {} +#endif // _LIBCPP_STD_VER >= 20 + _LIBCPP_INLINE_VISIBILITY basic_ostringstream(basic_ostringstream&& __rhs) : basic_ostream<_CharT, _Traits>(_VSTD::move(__rhs)) @@ -800,19 +1002,32 @@ return const_cast*>(&__sb_); } _LIBCPP_INLINE_VISIBILITY - string_type str() const { - return __sb_.str(); - } - _LIBCPP_INLINE_VISIBILITY void str(const string_type& __s) { __sb_.str(__s); } + #if _LIBCPP_STD_VER >= 20 - _LIBCPP_HIDE_FROM_ABI - basic_string_view view() const noexcept { - return __sb_.view(); + _LIBCPP_HIDE_FROM_ABI string_type str() const & { return __sb_.str(); } + + template + requires __is_allocator<_SAlloc>::value + _LIBCPP_HIDE_FROM_ABI basic_string str(const _SAlloc& __sa) const { + return __sb_.str(__sa); } -#endif + + _LIBCPP_HIDE_FROM_ABI string_type str() && { return std::move(__sb_).str(); } + + template + _LIBCPP_HIDE_FROM_ABI void str(const basic_string& __s) { + __sb_.str(__s); + } + + _LIBCPP_HIDE_FROM_ABI void str(string_type&& __s) { __sb_.str(std::move(__s)); } + + _LIBCPP_HIDE_FROM_ABI basic_string_view view() const noexcept { return __sb_.view(); } +#else // _LIBCPP_STD_VER >= 20 + _LIBCPP_HIDE_FROM_ABI string_type str() const { return __sb_.str(); } +#endif // _LIBCPP_STD_VER >= 20 }; template @@ -860,6 +1075,29 @@ , __sb_(__s, __wch) { } +#if _LIBCPP_STD_VER >= 20 + _LIBCPP_HIDE_FROM_ABI basic_stringstream(ios_base::openmode __wch, const _Allocator& __a) + : basic_iostream<_CharT, _Traits>(&__sb_), __sb_(__wch, __a) {} + + _LIBCPP_HIDE_FROM_ABI explicit basic_stringstream(string_type&& __s, + ios_base::openmode __wch = ios_base::in | ios_base::out) + : basic_iostream<_CharT, _Traits>(&__sb_), __sb_(std::move(__s), __wch) {} + + template + _LIBCPP_HIDE_FROM_ABI basic_stringstream(const basic_string<_CharT, _Traits, _SAlloc>& __s, const _Allocator& __a) + : basic_iostream<_CharT, _Traits>(&__sb_), __sb_(__s, ios_base::in | ios_base::out, __a) {} + + template + _LIBCPP_HIDE_FROM_ABI + basic_stringstream(const basic_string<_CharT, _Traits, _SAlloc>& __s, ios_base::openmode __wch, const _Allocator& __a) + : basic_iostream<_CharT, _Traits>(&__sb_), __sb_(__s, __wch, __a) {} + + template + _LIBCPP_HIDE_FROM_ABI explicit basic_stringstream(const basic_string<_CharT, _Traits, _SAlloc>& __s, + ios_base::openmode __wch = ios_base::in | ios_base::out) + : basic_iostream<_CharT, _Traits>(&__sb_), __sb_(__s, __wch) {} +#endif // _LIBCPP_STD_VER >= 20 + _LIBCPP_INLINE_VISIBILITY basic_stringstream(basic_stringstream&& __rhs) : basic_iostream<_CharT, _Traits>(_VSTD::move(__rhs)) @@ -886,19 +1124,31 @@ return const_cast*>(&__sb_); } _LIBCPP_INLINE_VISIBILITY - string_type str() const { - return __sb_.str(); - } - _LIBCPP_INLINE_VISIBILITY void str(const string_type& __s) { __sb_.str(__s); } #if _LIBCPP_STD_VER >= 20 - _LIBCPP_HIDE_FROM_ABI - basic_string_view view() const noexcept { - return __sb_.view(); + _LIBCPP_HIDE_FROM_ABI string_type str() const & { return __sb_.str(); } + + template + requires __is_allocator<_SAlloc>::value + _LIBCPP_HIDE_FROM_ABI basic_string str(const _SAlloc& __sa) const { + return __sb_.str(__sa); } -#endif + + _LIBCPP_HIDE_FROM_ABI string_type str() && { return std::move(__sb_).str(); } + + template + _LIBCPP_HIDE_FROM_ABI void str(const basic_string& __s) { + __sb_.str(__s); + } + + _LIBCPP_HIDE_FROM_ABI void str(string_type&& __s) { __sb_.str(std::move(__s)); } + + _LIBCPP_HIDE_FROM_ABI basic_string_view view() const noexcept { return __sb_.view(); } +#else // _LIBCPP_STD_VER >= 20 + _LIBCPP_HIDE_FROM_ABI string_type str() const { return __sb_.str(); } +#endif // _LIBCPP_STD_VER >= 20 }; template diff --git a/libcxx/test/std/input.output/string.streams/istringstream/istringstream.cons/alloc.pass.cpp b/libcxx/test/std/input.output/string.streams/istringstream/istringstream.cons/alloc.pass.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/std/input.output/string.streams/istringstream/istringstream.cons/alloc.pass.cpp @@ -0,0 +1,82 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// + +// template , class Allocator = allocator > +// class basic_istringstream + +// basic_istringstream(ios_base::openmode which, const Allocator& a); +// template +// basic_istringstream(const basic_string& s, const Allocator& a) +// : basic_istringstream(s, ios_base::in, a) {} +// template +// basic_istringstream(const basic_string& s, +// ios_base::openmode which, const Allocator& a); +// template +// explicit basic_istringstream(const basic_string& s, +// ios_base::openmode which = ios_base::in); + +#include +#include + +#include "make_string.h" +#include "test_allocator.h" +#include "test_macros.h" + +#define STR(S) MAKE_STRING(CharT, S) +#define SV(S) MAKE_STRING_VIEW(CharT, S) + +template +static void test() { + using test_istringstream = std::basic_istringstream, test_allocator>; + { + const test_allocator a(2); + const test_istringstream ss(std::ios_base::in, a); + assert(ss.view() == SV("")); + assert(ss.rdbuf()->get_allocator() == a); + } + { + const std::basic_string s(STR("testing")); + const test_allocator a(4); + const test_istringstream ss(s, a); + assert(ss.view() == SV("testing")); + assert(ss.rdbuf()->get_allocator() == a); + } + { + const std::basic_string s(STR("testing")); + const test_allocator a(5); + const test_istringstream ss(s, std::ios_base::in, a); + assert(ss.view() == SV("testing")); + assert(ss.rdbuf()->get_allocator() == a); + } + { + const test_allocator a(6); + const std::basic_string, test_allocator> s(STR("testing"), a); + const std::basic_istringstream ss(s); + assert(ss.view() == SV("testing")); + assert(ss.rdbuf()->get_allocator() == std::allocator()); + } + { + const test_allocator a(7); + const std::basic_string, test_allocator> s(STR("testing"), a); + const std::basic_istringstream ss(s, std::ios_base::in); + assert(ss.view() == SV("testing")); + assert(ss.rdbuf()->get_allocator() == std::allocator()); + } +} + +int main(int, char**) { + test(); +#ifndef TEST_HAS_NO_WIDE_CHARACTERS + test(); +#endif + return 0; +} diff --git a/libcxx/test/std/input.output/string.streams/istringstream/istringstream.cons/string.move.pass.cpp b/libcxx/test/std/input.output/string.streams/istringstream/istringstream.cons/string.move.pass.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/std/input.output/string.streams/istringstream/istringstream.cons/string.move.pass.cpp @@ -0,0 +1,49 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// + +// template , class Allocator = allocator > +// class basic_istringstream + +// explicit basic_istringstream(basic_string&& s, +// ios_base::openmode which = ios_base::in); + +#include +#include + +#include "test_macros.h" + +int main(int, char**) { + { + std::string s("testing"); + std::istringstream ss(std::move(s)); + assert(ss.view() == "testing"); + } + { + std::string s("testing"); + std::istringstream ss(std::move(s), std::ios_base::in); + assert(ss.view() == "testing"); + } +#ifndef TEST_HAS_NO_WIDE_CHARACTERS + { + std::wstring s(L"testing"); + std::wistringstream ss(std::move(s)); + assert(ss.view() == L"testing"); + } + { + std::wstring s(L"testing"); + std::wistringstream ss(std::move(s), std::ios_base::in); + assert(ss.view() == L"testing"); + } +#endif + + return 0; +} diff --git a/libcxx/test/std/input.output/string.streams/istringstream/istringstream.members/str.alloc.pass.cpp b/libcxx/test/std/input.output/string.streams/istringstream/istringstream.members/str.alloc.pass.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/std/input.output/string.streams/istringstream/istringstream.members/str.alloc.pass.cpp @@ -0,0 +1,55 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// + +// template , class Allocator = allocator > +// class basic_istringstream + +// template +// basic_string str(const SAlloc& sa) const; +// template +// void str(const basic_string& s); + +#include +#include + +#include "make_string.h" +#include "test_allocator.h" +#include "test_macros.h" + +#define STR(S) MAKE_STRING(CharT, S) +#define SV(S) MAKE_STRING_VIEW(CharT, S) + +template +static void test() { + { + const std::basic_istringstream ss(STR("testing")); + const test_allocator a(1); + const std::basic_string, test_allocator> s = ss.str(a); + assert(s == SV("testing")); + assert(s.get_allocator() == a); + } + { + const test_allocator a(6); + const std::basic_string, test_allocator> s(STR("testing"), a); + const std::basic_istringstream, test_allocator> ss(s); + assert(ss.view() == SV("testing")); + assert(ss.rdbuf()->get_allocator() == a); + } +} + +int main(int, char**) { + test(); +#ifndef TEST_HAS_NO_WIDE_CHARACTERS + test(); +#endif + return 0; +} diff --git a/libcxx/test/std/input.output/string.streams/istringstream/istringstream.members/str.move.pass.cpp b/libcxx/test/std/input.output/string.streams/istringstream/istringstream.members/str.move.pass.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/std/input.output/string.streams/istringstream/istringstream.members/str.move.pass.cpp @@ -0,0 +1,50 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// + +// template , class Allocator = allocator > +// class basic_istringstream + +// basic_string str() &&; +// void str(basic_string&& s); + +#include +#include + +#include "make_string.h" +#include "test_macros.h" + +#define STR(S) MAKE_STRING(CharT, S) +#define SV(S) MAKE_STRING_VIEW(CharT, S) + +template +static void test() { + { + std::basic_istringstream ss(STR("testing")); + std::basic_string s = std::move(ss).str(); + assert(s == SV("testing")); + assert(ss.view() == SV("")); + } + { + std::basic_istringstream ss; + std::basic_string s(STR("testing")); + ss.str(std::move(s)); + assert(ss.view() == SV("testing")); + } +} + +int main(int, char**) { + test(); +#ifndef TEST_HAS_NO_WIDE_CHARACTERS + test(); +#endif + return 0; +} diff --git a/libcxx/test/std/input.output/string.streams/ostringstream/ostringstream.cons/alloc.pass.cpp b/libcxx/test/std/input.output/string.streams/ostringstream/ostringstream.cons/alloc.pass.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/std/input.output/string.streams/ostringstream/ostringstream.cons/alloc.pass.cpp @@ -0,0 +1,82 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// + +// template , class Allocator = allocator > +// class basic_ostringstream + +// basic_ostringstream(ios_base::openmode which, const Allocator& a); +// template +// basic_ostringstream(const basic_string& s, const Allocator& a) +// : basic_ostringstream(s, ios_base::out, a) {} +// template +// basic_ostringstream(const basic_string& s, +// ios_base::openmode which, const Allocator& a); +// template +// explicit basic_ostringstream(const basic_string& s, +// ios_base::openmode which = ios_base::out); + +#include +#include + +#include "make_string.h" +#include "test_allocator.h" +#include "test_macros.h" + +#define STR(S) MAKE_STRING(CharT, S) +#define SV(S) MAKE_STRING_VIEW(CharT, S) + +template +static void test() { + using test_ostringstream = std::basic_ostringstream, test_allocator>; + { + const test_allocator a(2); + const test_ostringstream ss(std::ios_base::out, a); + assert(ss.view() == SV("")); + assert(ss.rdbuf()->get_allocator() == a); + } + { + const std::basic_string s(STR("testing")); + const test_allocator a(4); + const test_ostringstream ss(s, a); + assert(ss.view() == SV("testing")); + assert(ss.rdbuf()->get_allocator() == a); + } + { + const std::basic_string s(STR("testing")); + const test_allocator a(5); + const test_ostringstream ss(s, std::ios_base::out, a); + assert(ss.view() == SV("testing")); + assert(ss.rdbuf()->get_allocator() == a); + } + { + const test_allocator a(6); + const std::basic_string, test_allocator> s(STR("testing"), a); + const std::basic_ostringstream ss(s); + assert(ss.view() == SV("testing")); + assert(ss.rdbuf()->get_allocator() == std::allocator()); + } + { + const test_allocator a(7); + const std::basic_string, test_allocator> s(STR("testing"), a); + const std::basic_ostringstream ss(s, std::ios_base::out); + assert(ss.view() == SV("testing")); + assert(ss.rdbuf()->get_allocator() == std::allocator()); + } +} + +int main(int, char**) { + test(); +#ifndef TEST_HAS_NO_WIDE_CHARACTERS + test(); +#endif + return 0; +} diff --git a/libcxx/test/std/input.output/string.streams/ostringstream/ostringstream.cons/string.move.pass.cpp b/libcxx/test/std/input.output/string.streams/ostringstream/ostringstream.cons/string.move.pass.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/std/input.output/string.streams/ostringstream/ostringstream.cons/string.move.pass.cpp @@ -0,0 +1,49 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// + +// template , class Allocator = allocator > +// class basic_ostringstream + +// explicit basic_ostringstream(basic_string&& s, +// ios_base::openmode which = ios_base::out); + +#include +#include + +#include "test_macros.h" + +int main(int, char**) { + { + std::string s("testing"); + std::ostringstream ss(std::move(s)); + assert(ss.view() == "testing"); + } + { + std::string s("testing"); + std::ostringstream ss(std::move(s), std::ios_base::out); + assert(ss.view() == "testing"); + } +#ifndef TEST_HAS_NO_WIDE_CHARACTERS + { + std::wstring s(L"testing"); + std::wostringstream ss(std::move(s)); + assert(ss.view() == L"testing"); + } + { + std::wstring s(L"testing"); + std::wostringstream ss(std::move(s), std::ios_base::out); + assert(ss.view() == L"testing"); + } +#endif + + return 0; +} diff --git a/libcxx/test/std/input.output/string.streams/ostringstream/ostringstream.members/str.alloc.pass.cpp b/libcxx/test/std/input.output/string.streams/ostringstream/ostringstream.members/str.alloc.pass.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/std/input.output/string.streams/ostringstream/ostringstream.members/str.alloc.pass.cpp @@ -0,0 +1,55 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// + +// template , class Allocator = allocator > +// class basic_ostringstream + +// template +// basic_string str(const SAlloc& sa) const; +// template +// void str(const basic_string& s); + +#include +#include + +#include "make_string.h" +#include "test_allocator.h" +#include "test_macros.h" + +#define STR(S) MAKE_STRING(CharT, S) +#define SV(S) MAKE_STRING_VIEW(CharT, S) + +template +static void test() { + { + const std::basic_ostringstream ss(STR("testing")); + const test_allocator a(1); + const std::basic_string, test_allocator> s = ss.str(a); + assert(s == SV("testing")); + assert(s.get_allocator() == a); + } + { + const test_allocator a(6); + const std::basic_string, test_allocator> s(STR("testing"), a); + const std::basic_ostringstream, test_allocator> ss(s); + assert(ss.view() == SV("testing")); + assert(ss.rdbuf()->get_allocator() == a); + } +} + +int main(int, char**) { + test(); +#ifndef TEST_HAS_NO_WIDE_CHARACTERS + test(); +#endif + return 0; +} diff --git a/libcxx/test/std/input.output/string.streams/ostringstream/ostringstream.members/str.move.pass.cpp b/libcxx/test/std/input.output/string.streams/ostringstream/ostringstream.members/str.move.pass.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/std/input.output/string.streams/ostringstream/ostringstream.members/str.move.pass.cpp @@ -0,0 +1,50 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// + +// template , class Allocator = allocator > +// class basic_ostringstream + +// basic_string str() &&; +// void str(basic_string&& s); + +#include +#include + +#include "make_string.h" +#include "test_macros.h" + +#define STR(S) MAKE_STRING(CharT, S) +#define SV(S) MAKE_STRING_VIEW(CharT, S) + +template +static void test() { + { + std::basic_ostringstream ss(STR("testing")); + std::basic_string s = std::move(ss).str(); + assert(s == SV("testing")); + assert(ss.view() == SV("")); + } + { + std::basic_ostringstream ss; + std::basic_string s(STR("testing")); + ss.str(std::move(s)); + assert(ss.view() == SV("testing")); + } +} + +int main(int, char**) { + test(); +#ifndef TEST_HAS_NO_WIDE_CHARACTERS + test(); +#endif + return 0; +} diff --git a/libcxx/test/std/input.output/string.streams/stringbuf/stringbuf.cons/alloc.pass.cpp b/libcxx/test/std/input.output/string.streams/stringbuf/stringbuf.cons/alloc.pass.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/std/input.output/string.streams/stringbuf/stringbuf.cons/alloc.pass.cpp @@ -0,0 +1,104 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// + +// template , class Allocator = allocator > +// class basic_stringbuf + +// explicit basic_stringbuf(const Allocator& a) +// : basic_stringbuf(ios_base::in | ios_base::out, a) {} +// basic_stringbuf(ios_base::openmode which, const Allocator& a); +// template +// basic_stringbuf(const basic_string& s, const Allocator& a) +// : basic_stringbuf(s, ios_base::in | ios_base::out, a) {} +// template +// basic_stringbuf(const basic_string& s, +// ios_base::openmode which, const Allocator& a); +// template +// explicit basic_stringbuf(const basic_string& s, +// ios_base::openmode which = ios_base::in | ios_base::out); +// basic_stringbuf(basic_stringbuf&& rhs, const Allocator& a); + +#include +#include + +#include "make_string.h" +#include "test_allocator.h" +#include "test_macros.h" + +#define STR(S) MAKE_STRING(CharT, S) +#define SV(S) MAKE_STRING_VIEW(CharT, S) + +template +static void test() { + using test_stringbuf = std::basic_stringbuf, test_allocator>; + { + const test_allocator a(1); + const test_stringbuf buf(a); + assert(buf.view() == SV("")); + assert(buf.get_allocator() == a); + } + { + const test_allocator a(2); + const test_stringbuf buf(std::ios_base::in, a); + assert(buf.view() == SV("")); + assert(buf.get_allocator() == a); + } + { + const test_allocator a(3); + const test_stringbuf buf(std::ios_base::out, a); + assert(buf.view() == SV("")); + assert(buf.get_allocator() == a); + } + { + const std::basic_string s(STR("testing")); + const test_allocator a(4); + const test_stringbuf buf(s, a); + assert(buf.view() == SV("testing")); + assert(buf.get_allocator() == a); + } + { + const std::basic_string s(STR("testing")); + const test_allocator a(5); + const test_stringbuf buf(s, std::ios_base::in, a); + assert(buf.view() == SV("testing")); + assert(buf.get_allocator() == a); + } + { + const test_allocator a(6); + const std::basic_string, test_allocator> s(STR("testing"), a); + const std::basic_stringbuf buf(s); + assert(buf.view() == SV("testing")); + assert(buf.get_allocator() == std::allocator()); + } + { + const test_allocator a(7); + const std::basic_string, test_allocator> s(STR("testing"), a); + const std::basic_stringbuf buf(s, std::ios_base::in); + assert(buf.view() == SV("testing")); + assert(buf.get_allocator() == std::allocator()); + } + { + const test_allocator a(8); + test_stringbuf buf1(STR("testing"), a); + const test_stringbuf buf(std::move(buf1), a); + assert(buf.view() == SV("testing")); + assert(buf.get_allocator() == a); + } +} + +int main(int, char**) { + test(); +#ifndef TEST_HAS_NO_WIDE_CHARACTERS + test(); +#endif + return 0; +} diff --git a/libcxx/test/std/input.output/string.streams/stringbuf/stringbuf.cons/string.move.pass.cpp b/libcxx/test/std/input.output/string.streams/stringbuf/stringbuf.cons/string.move.pass.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/std/input.output/string.streams/stringbuf/stringbuf.cons/string.move.pass.cpp @@ -0,0 +1,59 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// + +// template , class Allocator = allocator > +// class basic_stringbuf + +// explicit basic_stringbuf(basic_string&& s, +// ios_base::openmode which = ios_base::in | ios_base::out); + +#include +#include + +#include "test_macros.h" + +int main(int, char**) { + { + std::string s("testing"); + std::stringbuf buf(std::move(s)); + assert(buf.view() == "testing"); + } + { + std::string s("testing"); + std::stringbuf buf(std::move(s), std::ios_base::in); + assert(buf.view() == "testing"); + } + { + std::string s("testing"); + std::stringbuf buf(std::move(s), std::ios_base::out); + assert(buf.view() == "testing"); + } +#ifndef TEST_HAS_NO_WIDE_CHARACTERS + { + std::wstring s(L"testing"); + std::wstringbuf buf(std::move(s)); + assert(buf.view() == L"testing"); + } + { + std::wstring s(L"testing"); + std::wstringbuf buf(std::move(s), std::ios_base::in); + assert(buf.view() == L"testing"); + } + { + std::wstring s(L"testing"); + std::wstringbuf buf(std::move(s), std::ios_base::out); + assert(buf.view() == L"testing"); + } +#endif + + return 0; +} diff --git a/libcxx/test/std/input.output/string.streams/stringbuf/stringbuf.members/str.alloc.pass.cpp b/libcxx/test/std/input.output/string.streams/stringbuf/stringbuf.members/str.alloc.pass.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/std/input.output/string.streams/stringbuf/stringbuf.members/str.alloc.pass.cpp @@ -0,0 +1,55 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// + +// template , class Allocator = allocator > +// class basic_stringbuf + +// template +// basic_string str(const SAlloc& sa) const; +// template +// void str(const basic_string& s); + +#include +#include + +#include "make_string.h" +#include "test_allocator.h" +#include "test_macros.h" + +#define STR(S) MAKE_STRING(CharT, S) +#define SV(S) MAKE_STRING_VIEW(CharT, S) + +template +static void test() { + { + const std::basic_stringbuf buf(STR("testing")); + const test_allocator a(1); + const std::basic_string, test_allocator> s = buf.str(a); + assert(s == SV("testing")); + assert(s.get_allocator() == a); + } + { + const test_allocator a(6); + const std::basic_string, test_allocator> s(STR("testing"), a); + const std::basic_stringbuf, test_allocator> buf(s); + assert(buf.view() == SV("testing")); + assert(buf.get_allocator() == a); + } +} + +int main(int, char**) { + test(); +#ifndef TEST_HAS_NO_WIDE_CHARACTERS + test(); +#endif + return 0; +} diff --git a/libcxx/test/std/input.output/string.streams/stringbuf/stringbuf.members/str.move.pass.cpp b/libcxx/test/std/input.output/string.streams/stringbuf/stringbuf.members/str.move.pass.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/std/input.output/string.streams/stringbuf/stringbuf.members/str.move.pass.cpp @@ -0,0 +1,50 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// + +// template , class Allocator = allocator > +// class basic_stringbuf + +// basic_string str() &&; +// void str(basic_string&& s); + +#include +#include + +#include "make_string.h" +#include "test_macros.h" + +#define STR(S) MAKE_STRING(CharT, S) +#define SV(S) MAKE_STRING_VIEW(CharT, S) + +template +static void test() { + { + std::basic_stringbuf buf(STR("testing")); + std::basic_string s = std::move(buf).str(); + assert(s == SV("testing")); + assert(buf.view() == SV("")); + } + { + std::basic_stringbuf buf; + std::basic_string s(STR("testing")); + buf.str(std::move(s)); + assert(buf.view() == SV("testing")); + } +} + +int main(int, char**) { + test(); +#ifndef TEST_HAS_NO_WIDE_CHARACTERS + test(); +#endif + return 0; +} diff --git a/libcxx/test/std/input.output/string.streams/stringstream/stringstream.cons/alloc.pass.cpp b/libcxx/test/std/input.output/string.streams/stringstream/stringstream.cons/alloc.pass.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/std/input.output/string.streams/stringstream/stringstream.cons/alloc.pass.cpp @@ -0,0 +1,82 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// + +// template , class Allocator = allocator > +// class basic_stringstream + +// basic_stringstream(ios_base::openmode which, const Allocator& a); +// template +// basic_stringstream(const basic_string& s, const Allocator& a) +// : basic_stringstream(s, ios_base::in | ios_base::out, a) {} +// template +// basic_stringstream(const basic_string& s, +// ios_base::openmode which, const Allocator& a); +// template +// explicit basic_stringstream(const basic_string& s, +// ios_base::openmode which = ios_base::in | ios_base::out); + +#include +#include + +#include "make_string.h" +#include "test_allocator.h" +#include "test_macros.h" + +#define STR(S) MAKE_STRING(CharT, S) +#define SV(S) MAKE_STRING_VIEW(CharT, S) + +template +static void test() { + using test_stringstream = std::basic_stringstream, test_allocator>; + { + const test_allocator a(2); + const test_stringstream ss(std::ios_base::in, a); + assert(ss.view() == SV("")); + assert(ss.rdbuf()->get_allocator() == a); + } + { + const std::basic_string s(STR("testing")); + const test_allocator a(4); + const test_stringstream ss(s, a); + assert(ss.view() == SV("testing")); + assert(ss.rdbuf()->get_allocator() == a); + } + { + const std::basic_string s(STR("testing")); + const test_allocator a(5); + const test_stringstream ss(s, std::ios_base::out, a); + assert(ss.view() == SV("testing")); + assert(ss.rdbuf()->get_allocator() == a); + } + { + const test_allocator a(6); + const std::basic_string, test_allocator> s(STR("testing"), a); + const std::basic_stringstream ss(s); + assert(ss.view() == SV("testing")); + assert(ss.rdbuf()->get_allocator() == std::allocator()); + } + { + const test_allocator a(7); + const std::basic_string, test_allocator> s(STR("testing"), a); + const std::basic_stringstream ss(s, std::ios_base::in); + assert(ss.view() == SV("testing")); + assert(ss.rdbuf()->get_allocator() == std::allocator()); + } +} + +int main(int, char**) { + test(); +#ifndef TEST_HAS_NO_WIDE_CHARACTERS + test(); +#endif + return 0; +} diff --git a/libcxx/test/std/input.output/string.streams/stringstream/stringstream.cons/string.move.pass.cpp b/libcxx/test/std/input.output/string.streams/stringstream/stringstream.cons/string.move.pass.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/std/input.output/string.streams/stringstream/stringstream.cons/string.move.pass.cpp @@ -0,0 +1,59 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// + +// template , class Allocator = allocator > +// class basic_stringstream + +// explicit basic_stringstream(basic_string&& s, +// ios_base::openmode which = ios_base::in | ios_base::out); + +#include +#include + +#include "test_macros.h" + +int main(int, char**) { + { + std::string s("testing"); + std::stringstream ss(std::move(s)); + assert(ss.view() == "testing"); + } + { + std::string s("testing"); + std::stringstream ss(std::move(s), std::ios_base::in); + assert(ss.view() == "testing"); + } + { + std::string s("testing"); + std::stringstream ss(std::move(s), std::ios_base::out); + assert(ss.view() == "testing"); + } +#ifndef TEST_HAS_NO_WIDE_CHARACTERS + { + std::wstring s(L"testing"); + std::wstringstream ss(std::move(s)); + assert(ss.view() == L"testing"); + } + { + std::wstring s(L"testing"); + std::wstringstream ss(std::move(s), std::ios_base::in); + assert(ss.view() == L"testing"); + } + { + std::wstring s(L"testing"); + std::wstringstream ss(std::move(s), std::ios_base::out); + assert(ss.view() == L"testing"); + } +#endif + + return 0; +} diff --git a/libcxx/test/std/input.output/string.streams/stringstream/stringstream.members/str.alloc.pass.cpp b/libcxx/test/std/input.output/string.streams/stringstream/stringstream.members/str.alloc.pass.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/std/input.output/string.streams/stringstream/stringstream.members/str.alloc.pass.cpp @@ -0,0 +1,55 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// + +// template , class Allocator = allocator > +// class basic_stringstream + +// template +// basic_string str(const SAlloc& sa) const; +// template +// void str(const basic_string& s); + +#include +#include + +#include "make_string.h" +#include "test_allocator.h" +#include "test_macros.h" + +#define STR(S) MAKE_STRING(CharT, S) +#define SV(S) MAKE_STRING_VIEW(CharT, S) + +template +static void test() { + { + const std::basic_stringstream ss(STR("testing")); + const test_allocator a(1); + const std::basic_string, test_allocator> s = ss.str(a); + assert(s == SV("testing")); + assert(s.get_allocator() == a); + } + { + const test_allocator a(6); + const std::basic_string, test_allocator> s(STR("testing"), a); + const std::basic_stringstream, test_allocator> ss(s); + assert(ss.view() == SV("testing")); + assert(ss.rdbuf()->get_allocator() == a); + } +} + +int main(int, char**) { + test(); +#ifndef TEST_HAS_NO_WIDE_CHARACTERS + test(); +#endif + return 0; +} diff --git a/libcxx/test/std/input.output/string.streams/stringstream/stringstream.members/str.move.pass.cpp b/libcxx/test/std/input.output/string.streams/stringstream/stringstream.members/str.move.pass.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/std/input.output/string.streams/stringstream/stringstream.members/str.move.pass.cpp @@ -0,0 +1,50 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// + +// template , class Allocator = allocator > +// class basic_stringstream + +// basic_string str() &&; +// void str(basic_string&& s); + +#include +#include + +#include "make_string.h" +#include "test_macros.h" + +#define STR(S) MAKE_STRING(CharT, S) +#define SV(S) MAKE_STRING_VIEW(CharT, S) + +template +static void test() { + { + std::basic_stringstream ss(STR("testing")); + std::basic_string s = std::move(ss).str(); + assert(s == SV("testing")); + assert(ss.view() == SV("")); + } + { + std::basic_stringstream ss; + std::basic_string s(STR("testing")); + ss.str(std::move(s)); + assert(ss.view() == SV("testing")); + } +} + +int main(int, char**) { + test(); +#ifndef TEST_HAS_NO_WIDE_CHARACTERS + test(); +#endif + return 0; +}