C++ Logo

std-proposals

Advanced search

Re: [std-proposals] .first() and .last() in strings

From: Jason McKesson <jmckesson_at_[hidden]>
Date: Fri, 3 May 2024 10:23:10 -0400
On Tue, Apr 30, 2024 at 1:24 PM Richard Hodges via Std-Proposals
<std-proposals_at_[hidden]> wrote:
>
> Can’t first() and last() be free functions?
> Then they would not increase the surface area of std::string, and they would work with any sequence.
>
>
> On Tue, 30 Apr 2024 at 11:28, Bo Persson via Std-Proposals <std-proposals_at_[hidden]> wrote:
>>
>> On 2024-04-30 at 09:16, Rhidian De Wit via Std-Proposals wrote:
>> > Hello everyone,
>> >
>> > I've finally had some time to write a small proposal for a small
>> > addition to std::string and std::string_view.
>> > I will later add the proposed wording, but I'd already be appreciative
>> > of whatever comments anyone might have.
>> >
>>
>> The usual objection to extending std::string is of course that the
>> interface is already *way* too big. Why not remove some parts instead?
>> (looking at find_last_not_of) :-)
>>
>> Objection 2 is that this is something that can already be done in the
>> existing language. Adding more ways to do the same thing is also nothing
>> that C++ desperately needs.
>>
>> Looking at the names, it is not immediately obvious how .first() is
>> related to .find_first_of(). Can this not cause confusion, similar to
>> clear() vs empty()?

`std::first` and `std::last` are very short words that can be
confusing for new users, mistaking them for `std::begin` and
`std::end`.

Furthermore, as algorithms, they would be unable to return the type of
the container, so they wouldn't be able to actually do the job
requested.

Received on 2024-05-03 14:23:22