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>& str, ios_base::openmode which = ios_base::in | ios_base::out);

-3- Effects: Constructs an object of class basic_stringbuf, initializing the base class with basic_streambuf()(27.5.2.1), and initializing _mode_ with _which_. Then calls str(_s_). copies the content of_str_ into the basic_stringbuf underlying character sequence. If _which_ & ios_base::out is true, initializes the output sequence such that pbase() points to the first underlying character, epptr() points one past the last underlying character, andpptr() is equal to epptr() if _which_ & ios_base::ateis true, otherwise pptr() is equal to pbase(). Ifwhich & ios_base::in is true, initializes the input sequence such that eback() and gptr() point to the first underlying character and egptr() 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_stringbuf underlying character sequence and initializes the input and output sequences according to _mode_.If_mode_ & ios_base::out is true, initializes the output sequence such that pbase() points to the first underlying character, epptr() points one past the last underlying character, and pptr()is equal to epptr() if _mode_ & ios_base::inis true, otherwise pptr() is equal to pbase(). Ifmode & ios_base::in is true, initializes the input sequence such that eback() and gptr() point to the first underlying character and egptr() points one past the last underlying character.

-3- Postconditions: If mode & ios_base::out is true,pbase() points to the first underlying character and(epptr() >= pbase() + s.size()) holds; in addition, ifmode & ios_base::in is true, (pptr() == pbase() + s.data()) holds, otherwise (pptr() == pbase())is true. If mode & ios_base::in is true,eback() points to the first underlying character, and(gptr() == eback()) and (egptr() == eback() + s.size()) hold.

[ Kona (2007) Moved to Ready. ]