Date: Sat, 7 Jan 2023 20:00:39 +0100
On 06/01/2023 17:28, Jason McKesson via Std-Proposals wrote:
>> so that we can do stuff like:
>>
>> string str("monkey5");
>> Func( string_view(str).remove_suffix(1u).remove_prefix(2u) );
> You could just do this:
>
> Func(string_view(str.begin()+1, str.end() - 2));
>
> This requires C++20 for the contiguous iterator support, but it does
> work. Note that the remove_* functions exhibit UB if you try to remove
> more characters than exist. So the fact that this too will exhibit UB
> in those situations is fine.
It's completely anti-ergonomic to have to do math like that.
Compare with something like Qt, where string classes have functions that
mutate in place and functions that return the mutated version:
QStringView view;
view.chop(N); // mutates in-place, returns void
view.chopped(N); // does not mutate, returns a new view
My 2 c,
>> so that we can do stuff like:
>>
>> string str("monkey5");
>> Func( string_view(str).remove_suffix(1u).remove_prefix(2u) );
> You could just do this:
>
> Func(string_view(str.begin()+1, str.end() - 2));
>
> This requires C++20 for the contiguous iterator support, but it does
> work. Note that the remove_* functions exhibit UB if you try to remove
> more characters than exist. So the fact that this too will exhibit UB
> in those situations is fine.
It's completely anti-ergonomic to have to do math like that.
Compare with something like Qt, where string classes have functions that
mutate in place and functions that return the mutated version:
QStringView view;
view.chop(N); // mutates in-place, returns void
view.chopped(N); // does not mutate, returns a new view
My 2 c,
-- Giuseppe D'Angelo | giuseppe.dangelo_at_[hidden] | Senior Software Engineer KDAB (France) S.A.S., a KDAB Group company Tel. France +33 (0)4 90 84 08 53, http://www.kdab.com KDAB - The Qt, C++ and OpenGL Experts
Received on 2023-01-07 19:00:43