Zero-length static array spec

Iain Buclaw via Digitalmars-d digitalmars-d at puremagic.com
Sat Feb 7 17:00:25 PST 2015


On 8 February 2015 at 00:51, Iain Buclaw <ibuclaw at gdcproject.org> wrote:
> On 7 February 2015 at 22:45, David Nadlinger via Digitalmars-d
> <digitalmars-d at puremagic.com> wrote:
>> On Saturday, 7 February 2015 at 15:04:52 UTC, Iain Buclaw wrote:
>>>
>>> a0.ptr == a1.ptr  // false, enforced by compiler. Comparison not actually
>>> emitted.
>>
>>
>> I don't think that's a viable option. It would lead to completely
>> unintuitive behavior like the following:
>>
>> ---
>> bool isEqual(T)(T a, T b) { return a == b; }
>>
>> int[0] a0;
>> int[1] a1;
>>
>> assert(a0.ptr != a1.ptr);
>> assert(isEqual(a0.ptr, a1.ptr));
>> ---
>>
>
> You should be able to solve this in the compiler.  For instance, can
> you define an array type to having a non-fixed size?
>
> Check if you can do something in terms of:
> ---
> int[1] a1;
> int[0:18446744073709551615] a0;  // size_t.max
> ---
>

To give another clue.

int[1] a1;  Is an array type with an index type whose range is 0..0
int[2] a2;  Is an array type with an index type whose range is 0..1
int[0] a0;  Is an array type with an index type whose range is 0..-1

The hint here is the range is always 0 .. size - 1

Iain.


More information about the Digitalmars-d mailing list