standard ranges

Timon Gehr timon.gehr at gmx.ch
Wed Jun 27 13:55:49 PDT 2012


On 06/27/2012 10:22 PM, Steven Schveighoffer wrote:
> On Wed, 27 Jun 2012 15:20:26 -0400, Timon Gehr <timon.gehr at gmx.ch> wrote:
>
>> There is no reason for anyone to be confused about this endlessly. It
>> is simple to understand. Furthermore, think about the implications of a
>> library-defined string type: it just introduces the problem of what the
>> type of built-in string literals should be. This would cause endless
>> pain with type deduction, ifti, string mixins, ... A library-defined
>> string type cannot be a full string type. Pretending that it can has no
>> value.
>
> Default type of the literal should be the library type.

Then it is not a library type, but a built-in type. Are you planning to
inject a dependency on Phobos into the compiler?

> If you want immutable(char)[], use "abc".codeunits or equivalent.
>

I really don't want to type .codeunits, but I want to use
immutable(char)[] everywhere. This 'library type' is just an interface
change that makes writing nice and efficient code a kludge.

> Of course, it should by default work as a zero-terminated char * for C
> compatibility.
>
> The current situation is not simple to understand.

It is simple, even if not immediately obvious. It does not have to be
immediately obvious without explanation. It needs to be convenient.

> Generic code that accepts arrays  has to special-case narrow-width strings if you plan to
> use phobos with them in some cases. That is a horrible situation.
>

Generic code accepts ranges, not arrays. All necessary (or maybe
unnecessary, I don't know) special casing is already done for you in
Phobos. The _only_ thing that is problematic is the inconsistent
'foreach' behaviour.

>> alias immutable(char)[] string is just fine.
>
> That is technically fine, but if phobos wants to treat immutable(char)[]
> as something other than an array, it is not fine.
>
> -Steve

Phobos does not treat immutable(char)[] as something other than an
array. It does not treat all arrays uniformly though.


More information about the Digitalmars-d mailing list