foo!(bar) ==> foo{bar}

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Wed Oct 8 09:14:05 PDT 2008


Benji Smith wrote:
> Andrei Alexandrescu wrote:
>> One possibility to make progress would be to keep !( but allow 
>> omitting the parens when only one argument is being passed. That way 
>> many instantiations will be helped. For example, in wake of the 
>> impending demise of complex built-ins:
>>
>> Complex!double alpha;
>> Complex!float[] data;
> 
> Is that an array of Complex!float, or a Complex of float-arrays?
> 
> In absence of parentheses, does the ! operator have higher precedence 
> than square brackets?
> 
> Also...just thinking aloud...it occurs to me that arrays really ought to 
> be templates, declared like this:
> 
>    Array!int integers;
> 
> The square-bracket declaration syntax is handy, but behind the scenes, 
> is there really any difference between an array-of-a-specific-type and a 
> template?

No difference so far as I know. Arrays and pointers are type 
constructors taking exactly one type.

template Array(T) { alias T[] Array; }
template Pointer(T) { alias T* Pointer; }

In fact it could be argued that this notation is more uniform, as [] and 
* are postfix and must be read right to left.


Andrei



More information about the Digitalmars-d mailing list