C++ Logo


Advanced search

Re: [std-proposals] Return type of string_view::remove_suffix

From: Jason McKesson <jmckesson_at_[hidden]>
Date: Fri, 6 Jan 2023 11:26:15 -0500
On Fri, Jan 6, 2023 at 11:13 AM Peter Olsson via Std-Proposals
<std-proposals_at_[hidden]> wrote:
> > Func( string_view(str).remove_suffix(1u).remove_prefix(2u) );
> One concern I have with this is that it becomes less clear that
> remove_suffix modifies the string_view object. This does not matter
> here but it might matter if called on a variable that gets used later.
> This might be a weak argument because append, replace and some
> overloads of insert already work the way you propose.

The thing is, string_view has *none* of those functions. `string_view`
is not immutable, but it's not really chainable.

I think it would be better to have separate functions that are
non-modifying which return a newly-modified string_view. That is, for
each modifying string_view function, there should be a non-modifying
one that returns a new `string_view`.

Received on 2023-01-06 16:26:25