C++ Logo

std-proposals

Advanced search

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

From: Peter Bindels <dascandy_at_[hidden]>
Date: Tue, 30 Apr 2024 09:48:32 +0200
Let me first say I like the basic premise.

+ It resembles the functions starts_with and ends_with that we recently
(2020) got
+ They make code easier to read and write.
- They make the huge interface that is std::string even bigger
- They offer a good looking but inefficient way to express starts_with and
ends_with on std::string - s.first(5) == "abcde". The paper is so terse
though that I don't know what the return value of first() would be on
std::string - does it return a string or a string_view? If it returns a
string it's inefficient. If it returns a string_view it's inconsistent with
the rest of std::string.
- How often would these functions be used? The functionality is already
captured and used often from within substr, and special-casing is fine if
there is a wide enough use for this. I don't know the numbers but would
need to know that it's serving a wide enough use case. I will admit that I
recognize writing `substr(0, X) and substr(X, str.size() - X) often enough
to know that I myself would have some use for them, but that doesn't
trivially extend to the whole community.

Thanks for the paper! I do hope you can make it into a full paper with the
information above, and I hope to see you at a standards meeting!

Peter





On Tue, Apr 30, 2024 at 9:17 AM Rhidian De Wit via Std-Proposals <
std-proposals_at_[hidden]> 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.
>
> Sincerely,
> --
> Rhidian De Wit
> Software Engineer - Barco
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>

Received on 2024-04-30 07:48:45