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. .. _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,17 +30,39 @@ 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: + allocator_type get_allocator() const noexcept; // C++20 basic_string str() const; void str(const basic_string& s); + 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: @@ -80,9 +102,20 @@ 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(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: @@ -92,7 +125,13 @@ // [istringstream.members] Member functions: basic_stringbuf* rdbuf() const; basic_string str() const; + 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 }; @@ -121,9 +160,20 @@ 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(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: @@ -133,7 +183,13 @@ // [ostringstream.members] Member functions: basic_stringbuf* rdbuf() const; basic_string str() const; + 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 }; @@ -159,12 +215,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: @@ -174,7 +241,13 @@ // [stringstream.members] Member functions: basic_stringbuf* rdbuf() const; basic_string str() const; - void str(const basic_string& str); + 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 }; @@ -205,6 +278,11 @@ _LIBCPP_PUSH_MACROS #include <__undef_macros> +#if _LIBCPP_STD_VER >= 20 +# define _LIBCPP_REF_SINCE_CXX20 & +#else +# define _LIBCPP_REF_SINCE_CXX20 +#endif _LIBCPP_BEGIN_NAMESPACE_STD @@ -229,6 +307,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,19 +328,86 @@ str(__s); } - basic_stringbuf(basic_stringbuf&& __rhs); + basic_stringbuf(basic_stringbuf&& __rhs) : __mode_(__rhs.__mode_) { __move_init(_VSTD::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_(_VSTD::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(_VSTD::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) + _NOEXCEPT_(allocator_traits::propagate_on_container_swap::value || + allocator_traits::is_always_equal::value); // [stringbuf.members] Member functions: - string_type str() const; - void str(const string_type& __s); + string_type str() const _LIBCPP_REF_SINCE_CXX20; + void str(const string_type& __s) { + __str_ = __s; + __init_buf_ptrs(); + } + #if _LIBCPP_STD_VER >= 20 - _LIBCPP_HIDE_FROM_ABI - basic_string_view view() const noexcept; -#endif + _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); + } + + _LIBCPP_HIDE_FROM_ABI string_type str() && { + basic_string_view<_CharT, _Traits> __view = view(); + return string_type(_VSTD::move(__str_), __view.begin() - __str_.data(), __view.size()); + } + + 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_ = _VSTD::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: @@ -277,9 +424,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,9 +511,9 @@ } template -void -basic_stringbuf<_CharT, _Traits, _Allocator>::swap(basic_stringbuf& __rhs) -{ +void basic_stringbuf<_CharT, _Traits, _Allocator>::swap(basic_stringbuf& __rhs) + _NOEXCEPT_(allocator_traits<_Allocator>::propagate_on_container_swap::value || + allocator_traits<_Allocator>::is_always_equal::value) { char_type* __p = const_cast(__rhs.__str_.data()); ptrdiff_t __rbinp = -1; ptrdiff_t __rninp = -1; @@ -443,20 +588,17 @@ } 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) + _NOEXCEPT_(noexcept(__x.swap(__y))) { __x.swap(__y); } template basic_string<_CharT, _Traits, _Allocator> -basic_stringbuf<_CharT, _Traits, _Allocator>::str() const -{ +basic_stringbuf<_CharT, _Traits, _Allocator>::str() const _LIBCPP_REF_SINCE_CXX20 { #if _LIBCPP_STD_VER >= 20 - return string_type(view(), __str_.get_allocator()); + return str(__str_.get_allocator()); #else // _LIBCPP_STD_VER >= 20 if (__mode_ & ios_base::out) { @@ -471,29 +613,20 @@ } 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 +820,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_(_VSTD::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 +868,32 @@ return const_cast*>(&__sb_); } _LIBCPP_INLINE_VISIBILITY - string_type str() const { + string_type str() const _LIBCPP_REF_SINCE_CXX20 { 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(); + 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 _VSTD::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(_VSTD::move(__s)); } + + _LIBCPP_HIDE_FROM_ABI basic_string_view view() const noexcept { return __sb_.view(); } +#endif // _LIBCPP_STD_VER >= 20 }; template @@ -773,6 +941,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_(_VSTD::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 +990,32 @@ return const_cast*>(&__sb_); } _LIBCPP_INLINE_VISIBILITY - string_type str() const { + string_type str() const _LIBCPP_REF_SINCE_CXX20 { 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(); + 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 _VSTD::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(_VSTD::move(__s)); } + + _LIBCPP_HIDE_FROM_ABI basic_string_view view() const noexcept { return __sb_.view(); } +#endif // _LIBCPP_STD_VER >= 20 }; template @@ -860,6 +1063,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_(_VSTD::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,7 +1112,7 @@ return const_cast*>(&__sb_); } _LIBCPP_INLINE_VISIBILITY - string_type str() const { + string_type str() const _LIBCPP_REF_SINCE_CXX20 { return __sb_.str(); } _LIBCPP_INLINE_VISIBILITY @@ -894,11 +1120,23 @@ __sb_.str(__s); } #if _LIBCPP_STD_VER >= 20 - _LIBCPP_HIDE_FROM_ABI - basic_string_view view() const noexcept { - return __sb_.view(); + 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 _VSTD::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(_VSTD::move(__s)); } + + _LIBCPP_HIDE_FROM_ABI basic_string_view view() const noexcept { return __sb_.view(); } +#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>; + { + test_allocator a(2); + test_istringstream ss(std::ios_base::in, a); + assert(ss.view() == SV("")); + assert(ss.rdbuf()->get_allocator() == a); + } + { + std::basic_string s(STR("testing")); + test_allocator a(4); + test_istringstream ss(s, a); + assert(ss.view() == SV("testing")); + assert(ss.rdbuf()->get_allocator() == a); + } + { + std::basic_string s(STR("testing")); + test_allocator a(5); + test_istringstream ss(s, std::ios_base::in, a); + assert(ss.view() == SV("testing")); + assert(ss.rdbuf()->get_allocator() == a); + } + { + test_allocator a(6); + std::basic_string, test_allocator> s(STR("testing"), a); + std::basic_istringstream ss(s); + assert(ss.view() == SV("testing")); + assert(ss.rdbuf()->get_allocator() == std::allocator()); + } + { + test_allocator a(7); + std::basic_string, test_allocator> s(STR("testing"), a); + 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() { + { + std::basic_istringstream ss(STR("testing")); + test_allocator a(1); + std::basic_string, test_allocator> s = ss.str(a); + assert(s == SV("testing")); + assert(s.get_allocator() == a); + } + { + test_allocator a(6); + std::basic_string, test_allocator> s(STR("testing"), a); + 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,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 + +// 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")); + } + { + 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>; + { + test_allocator a(2); + test_ostringstream ss(std::ios_base::out, a); + assert(ss.view() == SV("")); + assert(ss.rdbuf()->get_allocator() == a); + } + { + std::basic_string s(STR("testing")); + test_allocator a(4); + test_ostringstream ss(s, a); + assert(ss.view() == SV("testing")); + assert(ss.rdbuf()->get_allocator() == a); + } + { + std::basic_string s(STR("testing")); + test_allocator a(5); + test_ostringstream ss(s, std::ios_base::out, a); + assert(ss.view() == SV("testing")); + assert(ss.rdbuf()->get_allocator() == a); + } + { + test_allocator a(6); + std::basic_string, test_allocator> s(STR("testing"), a); + std::basic_ostringstream ss(s); + assert(ss.view() == SV("testing")); + assert(ss.rdbuf()->get_allocator() == std::allocator()); + } + { + test_allocator a(7); + std::basic_string, test_allocator> s(STR("testing"), a); + 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() { + { + std::basic_ostringstream ss(STR("testing")); + test_allocator a(1); + std::basic_string, test_allocator> s = ss.str(a); + assert(s == SV("testing")); + assert(s.get_allocator() == a); + } + { + test_allocator a(6); + std::basic_string, test_allocator> s(STR("testing"), a); + 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,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 + +// 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")); + } + { + 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>; + { + test_allocator a(1); + test_stringbuf buf(a); + assert(buf.view() == SV("")); + assert(buf.get_allocator() == a); + } + { + test_allocator a(2); + test_stringbuf buf(std::ios_base::in, a); + assert(buf.view() == SV("")); + assert(buf.get_allocator() == a); + } + { + test_allocator a(3); + test_stringbuf buf(std::ios_base::out, a); + assert(buf.view() == SV("")); + assert(buf.get_allocator() == a); + } + { + std::basic_string s(STR("testing")); + test_allocator a(4); + test_stringbuf buf(s, a); + assert(buf.view() == SV("testing")); + assert(buf.get_allocator() == a); + } + { + std::basic_string s(STR("testing")); + test_allocator a(5); + test_stringbuf buf(s, std::ios_base::in, a); + assert(buf.view() == SV("testing")); + assert(buf.get_allocator() == a); + } + { + test_allocator a(6); + std::basic_string, test_allocator> s(STR("testing"), a); + std::basic_stringbuf buf(s); + assert(buf.view() == SV("testing")); + assert(buf.get_allocator() == std::allocator()); + } + { + test_allocator a(7); + std::basic_string, test_allocator> s(STR("testing"), a); + std::basic_stringbuf buf(s, std::ios_base::in); + assert(buf.view() == SV("testing")); + assert(buf.get_allocator() == std::allocator()); + } + { + test_allocator a(8); + test_stringbuf buf1(STR("testing"), a); + 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() { + { + std::basic_stringbuf buf(STR("testing")); + test_allocator a(1); + std::basic_string, test_allocator> s = buf.str(a); + assert(s == SV("testing")); + assert(s.get_allocator() == a); + } + { + test_allocator a(6); + std::basic_string, test_allocator> s(STR("testing"), a); + 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,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_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")); + } + { + 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.cons/alloc.pass.cpp b/libcxx/test/std/input.output/string.streams/stringstream.cons/alloc.pass.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/std/input.output/string.streams/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>; + { + test_allocator a(2); + test_stringstream ss(std::ios_base::in, a); + assert(ss.view() == SV("")); + assert(ss.rdbuf()->get_allocator() == a); + } + { + std::basic_string s(STR("testing")); + test_allocator a(4); + test_stringstream ss(s, a); + assert(ss.view() == SV("testing")); + assert(ss.rdbuf()->get_allocator() == a); + } + { + std::basic_string s(STR("testing")); + test_allocator a(5); + test_stringstream ss(s, std::ios_base::out, a); + assert(ss.view() == SV("testing")); + assert(ss.rdbuf()->get_allocator() == a); + } + { + test_allocator a(6); + std::basic_string, test_allocator> s(STR("testing"), a); + std::basic_stringstream ss(s); + assert(ss.view() == SV("testing")); + assert(ss.rdbuf()->get_allocator() == std::allocator()); + } + { + test_allocator a(7); + std::basic_string, test_allocator> s(STR("testing"), a); + 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.cons/string.move.pass.cpp b/libcxx/test/std/input.output/string.streams/stringstream.cons/string.move.pass.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/std/input.output/string.streams/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.members/str.alloc.pass.cpp b/libcxx/test/std/input.output/string.streams/stringstream.members/str.alloc.pass.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/std/input.output/string.streams/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() { + { + std::basic_stringstream ss(STR("testing")); + test_allocator a(1); + std::basic_string, test_allocator> s = ss.str(a); + assert(s == SV("testing")); + assert(s.get_allocator() == a); + } + { + test_allocator a(6); + std::basic_string, test_allocator> s(STR("testing"), a); + 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.members/str.move.pass.cpp b/libcxx/test/std/input.output/string.streams/stringstream.members/str.move.pass.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/std/input.output/string.streams/stringstream.members/str.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_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")); + } + { + 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; +}