Narrow string is not a random access range

Jonathan M Davis jmdavisProg at gmx.com
Tue Oct 23 16:07:15 PDT 2012


On Wednesday, October 24, 2012 00:28:28 Timon Gehr wrote:
> The other valid opinion is that the 'mistake' is in Phobos because it
> treats narrow character arrays specially.

If it didn't, then range-based functions would be useless for strings in most 
cases, because it rarely makes sense to operate on code units.

> Note that string is just a name for immutable(char)[]. It would have to
> become a struct if random access was to be deprecated.

I think that Andrei was arguing for changing how the compiler itself handles 
arrays of char and wchar so that they wouldn't have direct random access or 
length anymore, forcing you to do something like str.rep[6] for random access 
regardless of what happens with range-based functions.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list