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

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Tue Oct 7 22:45:39 PDT 2008


Lionello Lunesu wrote:
> 
> "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.

Hmmmmmmm... there are multiple issues to discuss here.

One is, you want to compare ranges of different types. I agree that 
that's more general, e.g. a range could iterate const stuff and the 
other mutable stuff. But then which of the two range types do you 
return? You'd need some extra type pushups for that. But it's doable.

The other is more trivial: auto was supposed to save some typing, but 
the abundant typeof's in the signature considerably reduce that 
advantage. IMHO auto is useful when types are NOT restricted, and as far 
as I understand things now, future only has less of those.


Andrei



More information about the Digitalmars-d mailing list