string is rarely useful as a function argument
nospam at nospam.com
Sat Dec 31 04:15:42 PST 2011
On 31.12.2011 01:56, Timon Gehr wrote:
> On 12/31/2011 01:12 AM, Andrei Alexandrescu wrote:
>> On 12/30/11 6:07 PM, Timon Gehr wrote:
>>> alias std.string.representation raw;
>> I meant your implementation is incomplete.
> It was more a sketch than an implementation. It is not even type safe :o).
>> But the main point is that presence of representation/raw is not the
>> The availability of good-for-nothing .length and operator are
>> the issue. Putting in place the convention of using .raw is hardly
>> useful within the context.
> D strings are arrays. An array without .length and operator is close
> to being good for nothing. The language specification is quite clear
> about the fact that e.g. char is not a character but an utf-8 code unit.
> Therefore char is an array of code units.
No, it isn't. That's the problem. char is not an array of char.
It has an additional invariant: it is a UTF8 string. If you randomly
change elements, the invariant is violated.
In reality, char and wchar are compressed forms of dstring.
> .raw would return ubyte, therefore it
> would lose all type information. Effectively, what .raw does is a type
> cast that will let code point data alias with integral data.
Exactly. It's just a "I know what I'm doing" signal.
More information about the Digitalmars-d