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

Lionello Lunesu lionello at lunesu.remove.com
Tue Oct 7 22:08:01 PDT 2008


"Andrei Alexandrescu" <SeeWebsiteForEmail at erdani.org> wrote in message 
news:gch67k$1jl$1 at digitalmars.com...
> 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.

But this would do the same and, in fact, is more correct:

typeof(r1) overlap(auto r1, auto r2)
  if (isRandomAccessRange!(typeof(r1)) && isRandomAccessRange!(typeof(r2)))
{
    ...
}

The only thing the original (Range)(Range r1, Range r2) syntax adds, then,
is an implicit "if (typeof(r1) == typeof(r2))" constraint. If this
constraint is used often, that syntax can be retained, but would solely
affect the declaration of the template.

L. 




More information about the Digitalmars-d mailing list