Date: Fri, 6 Jan 2023 15:17:36 +0000
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) );
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) );
Received on 2023-01-06 15:17:48