C++ Logo


Advanced search

Re: [std-proposals] Adding a .slice() method to std::basic_string

From: Zhihao Yuan <zy_at_[hidden]>
Date: Tue, 12 Mar 2024 21:38:05 +0000
On Tuesday, March 12th, 2024 at 1:21 PM, Rhidian De Wit via Std-Proposals <std-proposals_at_[hidden]> wrote:

> Hi,
> C++ parsing has gotten a lot better since C++20 and C++23 with the introduction of string::ends_with() and string::contains(), but I feel like there's more to be gained.

If the proposal includes .first(N) and .last(N), similar
to std::span, we will be able to teach

  s.starts_with(s.first(N)) --> holds true
  s.ends_with(s.last(N)) --> holds true
  s.contains(s.slice(A, B)) --> holds true

If they return std::basic_string_view, the return type
will match starts_with/ends_with/contains's parameter
type perfectly.

Zhihao Yuan, ID lichray
The best way to predict the future is to invent it.

Received on 2024-03-12 21:38:20