Index: libcxx/include/sstream =================================================================== --- libcxx/include/sstream +++ libcxx/include/sstream @@ -41,6 +41,7 @@ // [stringbuf.members] Member functions: basic_string str() const; void str(const basic_string& s); + basic_string_view view() const noexcept; // C++20 protected: // [stringbuf.virtuals] Overridden virtual functions: @@ -92,6 +93,7 @@ basic_stringbuf* rdbuf() const; basic_string str() const; void str(const basic_string& s); + basic_string_view view() const noexcept; // C++20 }; template @@ -132,6 +134,7 @@ basic_stringbuf* rdbuf() const; basic_string str() const; void str(const basic_string& s); + basic_string_view view() const noexcept; // C++20 }; template @@ -172,6 +175,7 @@ basic_stringbuf* rdbuf() const; basic_string str() const; void str(const basic_string& str); + basic_string_view view() const noexcept; // C++20 }; template @@ -191,6 +195,7 @@ #include #include #include +#include #include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) @@ -252,6 +257,7 @@ // [stringbuf.members] Member functions: string_type str() const; void str(const string_type& __s); + basic_string_view view() const noexcept; // C++20 protected: // [stringbuf.virtuals] Overridden virtual functions: @@ -446,15 +452,7 @@ basic_string<_CharT, _Traits, _Allocator> 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) - return string_type(this->eback(), this->egptr(), __str_.get_allocator()); - return string_type(__str_.get_allocator()); + return string_type(this->view(), __str_.get_allocator()); } template @@ -490,6 +488,21 @@ } } +template +basic_string_view<_CharT, _Traits> +basic_stringbuf<_CharT, _Traits, _Allocator>::view() const noexcept +{ + if (__mode_ & ios_base::out) + { + if (__hm_ < this->pptr()) + __hm_ = this->pptr(); + return basic_string_view<_CharT, _Traits>(this->pbase(), __hm_ - this->pbase()); + } + else if (__mode_ & ios_base::in) + return basic_string_view<_CharT, _Traits>(this->eback(), this->egptr() - this->eback()); + return basic_string_view<_CharT, _Traits>(); +} + template typename basic_stringbuf<_CharT, _Traits, _Allocator>::int_type basic_stringbuf<_CharT, _Traits, _Allocator>::underflow() @@ -693,6 +706,10 @@ void str(const string_type& __s) { __sb_.str(__s); } + _LIBCPP_INLINE_VISIBILITY + basic_string_view view() const noexcept { + return __sb_.view(); + } }; template @@ -774,6 +791,10 @@ void str(const string_type& __s) { __sb_.str(__s); } + _LIBCPP_INLINE_VISIBILITY + basic_string_view view() const noexcept { + return __sb_.view(); + } }; template @@ -854,6 +875,10 @@ void str(const string_type& __s) { __sb_.str(__s); } + _LIBCPP_INLINE_VISIBILITY + basic_string_view view() const noexcept { + return __sb_.view(); + } }; template