Narrow string is not a random access range

Timon Gehr timon.gehr at gmx.ch
Tue Oct 23 16:33:28 PDT 2012


On 10/24/2012 01:07 AM, Jonathan M Davis wrote:
> 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
>

That idea does not even deserve discussion.


More information about the Digitalmars-d-learn mailing list