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

Denis Koroskin 2korden at gmail.com
Tue Oct 7 21:54:40 PDT 2008


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. 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?

> 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