Issue 562: stringbuf ctor inefficient (original) (raw)
This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of CD1 status.
562. stringbuf ctor inefficient
Section: 31.8 [string.streams] Status: CD1 Submitter: Martin Sebor Opened: 2006-02-23 Last modified: 2016-01-28
Priority: Not Prioritized
View all other issues in [string.streams].
View all issues with CD1 status.
Discussion:
For better efficiency, the requirement on the stringbuf ctor that takes a string argument should be loosened up to let it setepptr() beyond just one past the last initialized character just like overflow() has been changed to be allowed to do (see issue 432). That way the first call tosputc() on an object won't necessarily cause a call tooverflow. The corresponding change should be made to the string overload of the str() member function.
Proposed resolution:
Change 27.7.1.1, p3 of the Working Draft, N1804, as follows:
explicit basic_stringbuf(const basic_string<charT,traits,Allocator>& s
tr, ios_base::openmode which = ios_base::in | ios_base::out);-3- Effects: Constructs an object of class
basic_stringbuf, initializing the base class withbasic_streambuf()(27.5.2.1), and initializing_mode_with_which_. Then callsstr(_s_).copies the content of_str_ into thebasic_stringbufunderlying character sequence. If_which_ & ios_base::outis true, initializes the output sequence such thatpbase()points to the first underlying character,epptr()points one past the last underlying character, andpptr()is equal toepptr()if_which_ & ios_base::ateis true, otherwisepptr()is equal topbase(). Ifwhich & ios_base::inis true, initializes the input sequence such thateback()andgptr()point to the first underlying character andegptr()points one past the last underlying character.
Change the Effects clause of the str() in 27.7.1.2, p2 to read:
-2- Effects: Copies the contents of
_s_into thebasic_stringbufunderlying character sequence and initializes the input and output sequences according to_mode_.If_mode_ & ios_base::outis true, initializes the output sequence such thatpbase()points to the first underlying character,epptr()points one past the last underlying character, andpptr()is equal toepptr()if_mode_ & ios_base::inis true, otherwisepptr()is equal topbase(). Ifmode & ios_base::inis true, initializes the input sequence such thateback()andgptr()point to the first underlying character andegptr()points one past the last underlying character.-3- Postconditions: If
mode & ios_base::outis true,pbase()points to the first underlying character and(epptr() >= pbase() + s.size())holds; in addition, ifmode & ios_base::inis true,(pptr() == pbase() + s.data())holds, otherwise(pptr() == pbase())is true. Ifmode & ios_base::inis true,eback()points to the first underlying character, and(gptr() == eback())and(egptr() == eback() + s.size())hold.
[ Kona (2007) Moved to Ready. ]