From 4abb519619694de12e401de5454a6eed5c1384ea Mon Sep 17 00:00:00 2001 From: Louis Dionne Date: Fri, 9 Oct 2020 14:21:23 -0400 Subject: [PATCH] [libc++] NFCI: Define small methods of basic_stringstream inline It greatly increases readability because defining the methods out-of-line involves a ton of boilerplate template declarations. --- libcxx/include/sstream | 396 +++++++++++++++++-------------------------------- 1 file changed, 139 insertions(+), 257 deletions(-) diff --git a/libcxx/include/sstream b/libcxx/include/sstream index 4b1d17c..042766c 100644 --- a/libcxx/include/sstream +++ b/libcxx/include/sstream @@ -208,11 +208,19 @@ private: public: // 27.8.1.1 Constructors: - inline _LIBCPP_INLINE_VISIBILITY - explicit basic_stringbuf(ios_base::openmode __wch = ios_base::in | ios_base::out); - inline _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY + explicit basic_stringbuf(ios_base::openmode __wch = ios_base::in | ios_base::out) + : __hm_(0), __mode_(__wch) + { } + + _LIBCPP_INLINE_VISIBILITY explicit basic_stringbuf(const string_type& __s, - ios_base::openmode __wch = ios_base::in | ios_base::out); + ios_base::openmode __wch = ios_base::in | ios_base::out) + : __str_(__s.get_allocator()), __hm_(0), __mode_(__wch) + { + str(__s); + } + basic_stringbuf(basic_stringbuf&& __rhs); // 27.8.1.2 Assign and swap: @@ -230,29 +238,14 @@ protected: virtual int_type overflow (int_type __c = traits_type::eof()); virtual pos_type seekoff(off_type __off, ios_base::seekdir __way, ios_base::openmode __wch = ios_base::in | ios_base::out); - inline _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY virtual pos_type seekpos(pos_type __sp, - ios_base::openmode __wch = ios_base::in | ios_base::out); + ios_base::openmode __wch = ios_base::in | ios_base::out) { + return seekoff(__sp, ios_base::beg, __wch); + } }; template -basic_stringbuf<_CharT, _Traits, _Allocator>::basic_stringbuf(ios_base::openmode __wch) - : __hm_(0), - __mode_(__wch) -{ -} - -template -basic_stringbuf<_CharT, _Traits, _Allocator>::basic_stringbuf(const string_type& __s, - ios_base::openmode __wch) - : __str_(__s.get_allocator()), - __hm_(0), - __mode_(__wch) -{ - str(__s); -} - -template basic_stringbuf<_CharT, _Traits, _Allocator>::basic_stringbuf(basic_stringbuf&& __rhs) : __mode_(__rhs.__mode_) { @@ -609,14 +602,6 @@ basic_stringbuf<_CharT, _Traits, _Allocator>::seekoff(off_type __off, return pos_type(__noff); } -template -typename basic_stringbuf<_CharT, _Traits, _Allocator>::pos_type -basic_stringbuf<_CharT, _Traits, _Allocator>::seekpos(pos_type __sp, - ios_base::openmode __wch) -{ - return seekoff(__sp, ios_base::beg, __wch); -} - // basic_istringstream template @@ -638,68 +623,54 @@ private: public: // 27.8.2.1 Constructors: - inline _LIBCPP_INLINE_VISIBILITY - explicit basic_istringstream(ios_base::openmode __wch = ios_base::in); - inline _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY + explicit basic_istringstream(ios_base::openmode __wch = ios_base::in) + : basic_istream<_CharT, _Traits>(&__sb_) + , __sb_(__wch | ios_base::in) + { } + _LIBCPP_INLINE_VISIBILITY explicit basic_istringstream(const string_type& __s, - ios_base::openmode __wch = ios_base::in); - inline _LIBCPP_INLINE_VISIBILITY - basic_istringstream(basic_istringstream&& __rhs); + ios_base::openmode __wch = ios_base::in) + : basic_istream<_CharT, _Traits>(&__sb_) + , __sb_(__s, __wch | ios_base::in) + { } + + _LIBCPP_INLINE_VISIBILITY + basic_istringstream(basic_istringstream&& __rhs) + : basic_istream<_CharT, _Traits>(_VSTD::move(__rhs)) + , __sb_(_VSTD::move(__rhs.__sb_)) + { + basic_istream<_CharT, _Traits>::set_rdbuf(&__sb_); + } // 27.8.2.2 Assign and swap: - basic_istringstream& operator=(basic_istringstream&& __rhs); - inline _LIBCPP_INLINE_VISIBILITY - void swap(basic_istringstream& __rhs); + basic_istringstream& operator=(basic_istringstream&& __rhs) { + basic_istream::operator=(_VSTD::move(__rhs)); + __sb_ = _VSTD::move(__rhs.__sb_); + return *this; + } + _LIBCPP_INLINE_VISIBILITY + void swap(basic_istringstream& __rhs) { + basic_istream::swap(__rhs); + __sb_.swap(__rhs.__sb_); + } // 27.8.2.3 Members: - inline _LIBCPP_INLINE_VISIBILITY - basic_stringbuf* rdbuf() const; - inline _LIBCPP_INLINE_VISIBILITY - string_type str() const; - inline _LIBCPP_INLINE_VISIBILITY - void str(const string_type& __s); + _LIBCPP_INLINE_VISIBILITY + basic_stringbuf* rdbuf() const { + 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); + } }; template -basic_istringstream<_CharT, _Traits, _Allocator>::basic_istringstream(ios_base::openmode __wch) - : basic_istream<_CharT, _Traits>(&__sb_), - __sb_(__wch | ios_base::in) -{ -} - -template -basic_istringstream<_CharT, _Traits, _Allocator>::basic_istringstream(const string_type& __s, - ios_base::openmode __wch) - : basic_istream<_CharT, _Traits>(&__sb_), - __sb_(__s, __wch | ios_base::in) -{ -} - -template -basic_istringstream<_CharT, _Traits, _Allocator>::basic_istringstream(basic_istringstream&& __rhs) - : basic_istream<_CharT, _Traits>(_VSTD::move(__rhs)), - __sb_(_VSTD::move(__rhs.__sb_)) -{ - basic_istream<_CharT, _Traits>::set_rdbuf(&__sb_); -} - -template -basic_istringstream<_CharT, _Traits, _Allocator>& -basic_istringstream<_CharT, _Traits, _Allocator>::operator=(basic_istringstream&& __rhs) -{ - basic_istream::operator=(_VSTD::move(__rhs)); - __sb_ = _VSTD::move(__rhs.__sb_); - return *this; -} - -template -void basic_istringstream<_CharT, _Traits, _Allocator>::swap(basic_istringstream& __rhs) -{ - basic_istream::swap(__rhs); - __sb_.swap(__rhs.__sb_); -} - -template inline _LIBCPP_INLINE_VISIBILITY void swap(basic_istringstream<_CharT, _Traits, _Allocator>& __x, @@ -708,26 +679,6 @@ swap(basic_istringstream<_CharT, _Traits, _Allocator>& __x, __x.swap(__y); } -template -basic_stringbuf<_CharT, _Traits, _Allocator>* -basic_istringstream<_CharT, _Traits, _Allocator>::rdbuf() const -{ - return const_cast*>(&__sb_); -} - -template -basic_string<_CharT, _Traits, _Allocator> -basic_istringstream<_CharT, _Traits, _Allocator>::str() const -{ - return __sb_.str(); -} - -template -void basic_istringstream<_CharT, _Traits, _Allocator>::str(const string_type& __s) -{ - __sb_.str(__s); -} - // basic_ostringstream template @@ -749,69 +700,56 @@ private: public: // 27.8.2.1 Constructors: - inline _LIBCPP_INLINE_VISIBILITY - explicit basic_ostringstream(ios_base::openmode __wch = ios_base::out); - inline _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY + explicit basic_ostringstream(ios_base::openmode __wch = ios_base::out) + : basic_ostream<_CharT, _Traits>(&__sb_) + , __sb_(__wch | ios_base::out) + { } + + _LIBCPP_INLINE_VISIBILITY explicit basic_ostringstream(const string_type& __s, - ios_base::openmode __wch = ios_base::out); - inline _LIBCPP_INLINE_VISIBILITY - basic_ostringstream(basic_ostringstream&& __rhs); + ios_base::openmode __wch = ios_base::out) + : basic_ostream<_CharT, _Traits>(&__sb_) + , __sb_(__s, __wch | ios_base::out) + { } + + _LIBCPP_INLINE_VISIBILITY + basic_ostringstream(basic_ostringstream&& __rhs) + : basic_ostream<_CharT, _Traits>(_VSTD::move(__rhs)) + , __sb_(_VSTD::move(__rhs.__sb_)) + { + basic_ostream<_CharT, _Traits>::set_rdbuf(&__sb_); + } // 27.8.2.2 Assign and swap: - basic_ostringstream& operator=(basic_ostringstream&& __rhs); - inline _LIBCPP_INLINE_VISIBILITY - void swap(basic_ostringstream& __rhs); + basic_ostringstream& operator=(basic_ostringstream&& __rhs) { + basic_ostream::operator=(_VSTD::move(__rhs)); + __sb_ = _VSTD::move(__rhs.__sb_); + return *this; + } + + _LIBCPP_INLINE_VISIBILITY + void swap(basic_ostringstream& __rhs) { + basic_ostream::swap(__rhs); + __sb_.swap(__rhs.__sb_); + } // 27.8.2.3 Members: - inline _LIBCPP_INLINE_VISIBILITY - basic_stringbuf* rdbuf() const; - inline _LIBCPP_INLINE_VISIBILITY - string_type str() const; - inline _LIBCPP_INLINE_VISIBILITY - void str(const string_type& __s); + _LIBCPP_INLINE_VISIBILITY + basic_stringbuf* rdbuf() const { + 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); + } }; template -basic_ostringstream<_CharT, _Traits, _Allocator>::basic_ostringstream(ios_base::openmode __wch) - : basic_ostream<_CharT, _Traits>(&__sb_), - __sb_(__wch | ios_base::out) -{ -} - -template -basic_ostringstream<_CharT, _Traits, _Allocator>::basic_ostringstream(const string_type& __s, - ios_base::openmode __wch) - : basic_ostream<_CharT, _Traits>(&__sb_), - __sb_(__s, __wch | ios_base::out) -{ -} - -template -basic_ostringstream<_CharT, _Traits, _Allocator>::basic_ostringstream(basic_ostringstream&& __rhs) - : basic_ostream<_CharT, _Traits>(_VSTD::move(__rhs)), - __sb_(_VSTD::move(__rhs.__sb_)) -{ - basic_ostream<_CharT, _Traits>::set_rdbuf(&__sb_); -} - -template -basic_ostringstream<_CharT, _Traits, _Allocator>& -basic_ostringstream<_CharT, _Traits, _Allocator>::operator=(basic_ostringstream&& __rhs) -{ - basic_ostream::operator=(_VSTD::move(__rhs)); - __sb_ = _VSTD::move(__rhs.__sb_); - return *this; -} - -template -void -basic_ostringstream<_CharT, _Traits, _Allocator>::swap(basic_ostringstream& __rhs) -{ - basic_ostream::swap(__rhs); - __sb_.swap(__rhs.__sb_); -} - -template inline _LIBCPP_INLINE_VISIBILITY void swap(basic_ostringstream<_CharT, _Traits, _Allocator>& __x, @@ -820,27 +758,6 @@ swap(basic_ostringstream<_CharT, _Traits, _Allocator>& __x, __x.swap(__y); } -template -basic_stringbuf<_CharT, _Traits, _Allocator>* -basic_ostringstream<_CharT, _Traits, _Allocator>::rdbuf() const -{ - return const_cast*>(&__sb_); -} - -template -basic_string<_CharT, _Traits, _Allocator> -basic_ostringstream<_CharT, _Traits, _Allocator>::str() const -{ - return __sb_.str(); -} - -template -void -basic_ostringstream<_CharT, _Traits, _Allocator>::str(const string_type& __s) -{ - __sb_.str(__s); -} - // basic_stringstream template @@ -862,69 +779,55 @@ private: public: // 27.8.2.1 Constructors: - inline _LIBCPP_INLINE_VISIBILITY - explicit basic_stringstream(ios_base::openmode __wch = ios_base::in | ios_base::out); - inline _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY + explicit basic_stringstream(ios_base::openmode __wch = ios_base::in | ios_base::out) + : basic_iostream<_CharT, _Traits>(&__sb_) + , __sb_(__wch) + { } + + _LIBCPP_INLINE_VISIBILITY explicit basic_stringstream(const string_type& __s, - ios_base::openmode __wch = ios_base::in | ios_base::out); - inline _LIBCPP_INLINE_VISIBILITY - basic_stringstream(basic_stringstream&& __rhs); + ios_base::openmode __wch = ios_base::in | ios_base::out) + : basic_iostream<_CharT, _Traits>(&__sb_) + , __sb_(__s, __wch) + { } + + _LIBCPP_INLINE_VISIBILITY + basic_stringstream(basic_stringstream&& __rhs) + : basic_iostream<_CharT, _Traits>(_VSTD::move(__rhs)) + , __sb_(_VSTD::move(__rhs.__sb_)) + { + basic_istream<_CharT, _Traits>::set_rdbuf(&__sb_); + } // 27.8.2.2 Assign and swap: - basic_stringstream& operator=(basic_stringstream&& __rhs); - inline _LIBCPP_INLINE_VISIBILITY - void swap(basic_stringstream& __rhs); + basic_stringstream& operator=(basic_stringstream&& __rhs) { + basic_iostream::operator=(_VSTD::move(__rhs)); + __sb_ = _VSTD::move(__rhs.__sb_); + return *this; + } + _LIBCPP_INLINE_VISIBILITY + void swap(basic_stringstream& __rhs) { + basic_iostream::swap(__rhs); + __sb_.swap(__rhs.__sb_); + } // 27.8.2.3 Members: - inline _LIBCPP_INLINE_VISIBILITY - basic_stringbuf* rdbuf() const; - inline _LIBCPP_INLINE_VISIBILITY - string_type str() const; - inline _LIBCPP_INLINE_VISIBILITY - void str(const string_type& __s); + _LIBCPP_INLINE_VISIBILITY + basic_stringbuf* rdbuf() const { + 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); + } }; template -basic_stringstream<_CharT, _Traits, _Allocator>::basic_stringstream(ios_base::openmode __wch) - : basic_iostream<_CharT, _Traits>(&__sb_), - __sb_(__wch) -{ -} - -template -basic_stringstream<_CharT, _Traits, _Allocator>::basic_stringstream(const string_type& __s, - ios_base::openmode __wch) - : basic_iostream<_CharT, _Traits>(&__sb_), - __sb_(__s, __wch) -{ -} - -template -basic_stringstream<_CharT, _Traits, _Allocator>::basic_stringstream(basic_stringstream&& __rhs) - : basic_iostream<_CharT, _Traits>(_VSTD::move(__rhs)), - __sb_(_VSTD::move(__rhs.__sb_)) -{ - basic_istream<_CharT, _Traits>::set_rdbuf(&__sb_); -} - -template -basic_stringstream<_CharT, _Traits, _Allocator>& -basic_stringstream<_CharT, _Traits, _Allocator>::operator=(basic_stringstream&& __rhs) -{ - basic_iostream::operator=(_VSTD::move(__rhs)); - __sb_ = _VSTD::move(__rhs.__sb_); - return *this; -} - -template -void -basic_stringstream<_CharT, _Traits, _Allocator>::swap(basic_stringstream& __rhs) -{ - basic_iostream::swap(__rhs); - __sb_.swap(__rhs.__sb_); -} - -template inline _LIBCPP_INLINE_VISIBILITY void swap(basic_stringstream<_CharT, _Traits, _Allocator>& __x, @@ -933,27 +836,6 @@ swap(basic_stringstream<_CharT, _Traits, _Allocator>& __x, __x.swap(__y); } -template -basic_stringbuf<_CharT, _Traits, _Allocator>* -basic_stringstream<_CharT, _Traits, _Allocator>::rdbuf() const -{ - return const_cast*>(&__sb_); -} - -template -basic_string<_CharT, _Traits, _Allocator> -basic_stringstream<_CharT, _Traits, _Allocator>::str() const -{ - return __sb_.str(); -} - -template -void -basic_stringstream<_CharT, _Traits, _Allocator>::str(const string_type& __s) -{ - __sb_.str(__s); -} - _LIBCPP_END_NAMESPACE_STD _LIBCPP_POP_MACROS -- 2.7.4