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

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Tue Oct 7 19:33:32 PDT 2008


Michel Fortin wrote:
> On 2008-10-07 21:13:40 -0400, "Lionello Lunesu" 
> <lionello at lunesu.remove.com> said:
> 
>> I think more effort should be spent on unifying template and normal code.
>>
>> Partial compilation and "auto" support in the argument list might make 
>> the whole template syntax obsolete, since the compiler could issue a 
>> specially compiled version for constant argument values / argument 
>> types. Add to that support for "alias" template parameters in a normal 
>> argument list and we're on the right track:
>>
>> typeof(r1) overlap(auto r1, auto r2)
>>  if (typeof(r1) == typeof(r2))//not really ok but it's what 
>> algorithm.d has now
>> {
>> //...
>> }
>>
>> typeof(rs) filter(alias pred, auto[] rs ...)
>> {
>> //...
>> }
>>
>> I suppose we'd also need a way to force compilation of specific 
>> instantiations for inclusion in precompiled libraries.
>>
>> Please let me know if I'm talking BS here....
> 
> I think this is great concept... "implicit template functions"! You're 
> right that it cannot be included in precompiled libraries because it has 
> to be instanciated once you know the type of your arguments, but this 
> hasn't stopped templates from being used up to now.

I, too, think it's a nice idea. Walter, Bartosz and I discussed it a 
while ago. There are some savings in the declaration part, and no loss 
because you can always say typeof(arg) to figure out what the type was. 
In general, however, with the advent of conditional templates, I suspect 
that most templates will impose restrictions on the types of their 
arguments and therefore will need their type names. On the example given:

Range overlap(Range r1, Range r2) if (isRandomAccessRange!(Range))
{
     ...
}

The signature clarifies the requirements on the type much crisper than 
the loose, vale tudo:

auto overlap(auto r1, auto r2) { ... }

which will (1) catch every call (blech) and (2) attempt to plow through 
its implementation and fail to compile with an uninformative message, 
file, and line.


Andrei



More information about the Digitalmars-d mailing list