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

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Tue Oct 7 22:40:33 PDT 2008


Denis Koroskin wrote:
> On Wed, 08 Oct 2008 06:33:32 +0400, Andrei Alexandrescu 
> <SeeWebsiteForEmail at erdani.org> wrote:
> 
>> 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))
>> {
>>      ...
>> }
>>
> 
> Note that you didn't specify template arguments in the example above 
> (intensionally or not, you missed the "(Range)" part after function 
> name). It clearly says that you don't want to type that one.

Hehe. Damn. I did mean to type it.

As much as I don't want to type it, I have to. Otherwise the poor 
compiler can't know whether I meant to introduce Range or use a 
previously-defined Range.

> Also note 
> that the definition above is clearly a template function definition 
> since usual function lack matching mechanism (provided by 'if' part). 
> How easy it would be to compiler to detect, deduce and allow dropping 
> the template arguments?

Unfeasibly easy. Consider:

void foo(Bar bar, Baz baz) if (is(Bar : Baz)) { ... }

Now you tell me: which of Bar, Baz, or both is introduced, and which is 
to be looked up, if any?


Andrei




More information about the Digitalmars-d mailing list