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.

### 534. Missing basic_string members

Section: 23.4.3 [basic.string] Status: CD1 Submitter: Alisdair Meredith Opened: 2005-11-16 Last modified: 2016-01-28

Priority: Not Prioritized

View other active issues in [basic.string].

View all other issues in [basic.string].

View all issues with CD1 status.

Discussion:

OK, we all know std::basic_string is bloated and already has way too many members. However, I propose it is missing 3 useful members that are often expected by users believing it is a close approximation of the container concept. All 3 are listed in table 71 as 'optional'

i/ pop_back.

This is the one I feel most strongly about, as I only just discovered it was missing as we are switching to a more conforming standard library <g>

I find it particularly inconsistent to support push_back, but not pop_back.

ii/ back.

There are certainly cases where I want to examine the last character of a string before deciding to append, or to trim trailing path separators from directory names etc. *rbegin() somehow feels inelegant.

iii/ front

This one I don't feel strongly about, but if I can get the first two, this one feels that it should be added as a 'me too' for consistency.

I believe this would be similarly useful to the data() member recently added to vector, or at() member added to the maps.

Proposed resolution:

Add the following members to definition of class template basic_string, 21.3p7

>     void pop_back ()

>     const charT & front() const
>     charT & front()

>     const charT & back() const
>     charT & back()

Add the following paragraphs to basic_string description

21.3.4p5

>     const charT & front() const
>     charT & front()

> Precondition: `!empty()`

> Effects: Equivalent to `operator[](0)`.

21.3.4p6

>     const charT & back() const
>     charT & back()

> Precondition: `!empty()`

> Effects: Equivalent to `operator[]( size() - 1)`.

21.3.5.5p10

>     void pop_back ()

> Precondition: `!empty()`

> Effects: Equivalent to `erase( size() - 1, 1 )`.

Update Table 71: (optional sequence operations) Add basic_string to the list of containers for the following operations.

>     a.front()
>     a.back()
>     a.push_back()
>     a.pop_back()
>     a[n]

[ Berlin: Has support. Alisdair provided wording. ]