Date: Fri, 06 Jan 2023 15:38:47 +0000
On 6 January 2023 15:17:36 UTC, Frederick Virchanza Gotham via Std-Proposals <std-proposals_at_[hidden]> wrote:
>I had a function like this:
>
> extern void Func(string_view);
>
>And I wanted to call it as follows:
>
> string str("monkey5");
> Func( string_view(str).remove_suffix(1u) ); // remove the '5'
>
>but this didn't compiler because 'remove_suffix' returns void.
>
>Would it not have made sense for 'remove_suffix' to be defined as:
>
>class std::string_view {
> string_view &remove_suffix(size_t) &;
> string_view &&remove_suffix(size_t) &&;
> string_view &remove_prefix(size_t) &;
> string_view &&remove_prefix(size_t) &&;
>};
>
>so that we can do stuff like:
>
> string str("monkey5");
> Func( string_view(str).remove_suffix(1u).remove_prefix(2u) );
Why the overloads?
string_view should be returned by copy
I suppose it returns void because std::string member function returns void
>I had a function like this:
>
> extern void Func(string_view);
>
>And I wanted to call it as follows:
>
> string str("monkey5");
> Func( string_view(str).remove_suffix(1u) ); // remove the '5'
>
>but this didn't compiler because 'remove_suffix' returns void.
>
>Would it not have made sense for 'remove_suffix' to be defined as:
>
>class std::string_view {
> string_view &remove_suffix(size_t) &;
> string_view &&remove_suffix(size_t) &&;
> string_view &remove_prefix(size_t) &;
> string_view &&remove_prefix(size_t) &&;
>};
>
>so that we can do stuff like:
>
> string str("monkey5");
> Func( string_view(str).remove_suffix(1u).remove_prefix(2u) );
Why the overloads?
string_view should be returned by copy
I suppose it returns void because std::string member function returns void
Received on 2023-01-06 15:38:53