Syntax-wise it would be nearer to Python.

 

However it would be further from 2-dimensional arrays.

 

Alternative - I am not sure myself about it:

You could also consider adding a word, e.g. my_string[range_from_to{5, 10}], my_string[range_from_length{5, 10}];
 

-----Ursprüngliche Nachricht-----
Von: Breno Guimarães via Std-Proposals <std-proposals@lists.isocpp.org>
Gesendet: Mo 18.03.2024 14:16
Betreff: Re: [std-proposals] String Slicing Draft Proposal
An: std-proposals@lists.isocpp.org;
CC: Breno Guimarães <brenorg@gmail.com>; Rhidian De Wit <rhidiandewit@gmail.com>;
Hi,
 
Since C++23, it's now possible to use multi indexing: https://en.cppreference.com/w/cpp/language/operators#Array_subscript_operator
So it would come naturally to add the overload:
constexpr basic_string_view  basic_string::operator[](size_t start, size_t end) const;
That would allow the syntax to be very close to python:
if (my_string[5,10] == "something") { ... }
 
Has that been considered?
 
Best REgards,
Breno G.