On Tue, Mar 19, 2024, 4:36 AM Zhihao Yuan via Std-Proposals <std-proposals@lists.isocpp.org> wrote:
On Monday, March 18th, 2024 at 7:59 AM, Jonathan Wakely via Std-Proposals <std-proposals@lists.isocpp.org> wrote:

>

> I assume the suggestion is that it would be confusing for matrix[x,y]
> to return an element of the matrix, but str[i,j] to return a slice of
> the string. It would be using the same syntax for two different
> things.

I considered this syntax but did not suggest
it for the same reason. Moreover, unlike
Python or MATLAB, we don't have a syntax for
implied bounds (s[i:] and s[:j]), so s[i, j]
doesn't buy you much.

--
Zhihao Yuan, ID lichray
The best way to predict the future is to invent it.

If we can actually spell this s[i:j] (and as Zhihao points out also s[:j] and s[i:]), then I think that's worth pursuing and useful. In this context, I think "j" is very clearly a position rather than a length. 

But just adding a s.slice(i, j) that looks identical to s.susbtr(i, j)? Doesn't seem worth it. s[i, j] seems actively bad - you can slice multi-dimensional arrays too, so using identical syntax for slicing and indexing isn't a good idea. 

Barry