C++ Logo

std-proposals

Advanced search

Re: [std-proposals] String Slicing Draft Proposal

From: Jonathan Wakely <cxx_at_[hidden]>
Date: Tue, 26 Mar 2024 21:13:57 +0000
On Tue, 26 Mar 2024 at 11:37, Rhidian De Wit via Std-Proposals <
std-proposals_at_[hidden]> wrote:

> Hi,
>
> It returns a view in case it is called on a std::string_view, but a
> std::string returning a std::string_view could lead to far more confusion,
> since a string_view cannot be used in the same way as a string.
> If the user wants a string_view, they can either explicitly construct a
> string_view from the returned std::string, or they can call .subview() from
> a string_view.
>
> It is possible that someone uses subview() instead of substr() and might
> be confused by the displayed behaviour, but that is then on the end-user to
> check documentation and see what .subview() actually does.
>
>
Or they could use substr and consult the docs for what that does, and so
not need a new function at all.

Received on 2024-03-26 21:15:15