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 set `epptr()` 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 to `sputc()` on an object won't necessarily cause a call to `overflow`. 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, and `pptr()` is equal to `epptr()` if `which & ios_base::ate` is true, otherwise `pptr()` is equal to `pbase()`. If `which & 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 the `basic_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::in` is true, otherwise `pptr()` is equal to `pbase()`. If `mode & 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, if `mode & 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. ]