Partial return type specification

Peter Alexander peter.alexander.au at gmail.com
Tue Oct 12 10:35:23 PDT 2010


On 12/10/10 7:28 AM, Pelle wrote:
> On 10/11/2010 10:56 PM, bearophile wrote:
>> Ideally the partial specification syntax for ranges may work at the
>> calling point too:
>>
>> void main() {
>> Range!int results = foo();
>> }
>>
>> Here results is of its specific type, it's not a "Range!int", so
>> Range!int works as "auto". The difference is that the compiler makes
>> sure that's an iterable of ints, and not an iterable of floats or a
>> not iterable, etc.
>>
>> Bye,
>> bearophile
>
> This I would very much like. Also, being able to specify that you return
> a Range!int or ForwardRange!int would be very useful. Without losing the
> value types, of course. :-)

So basically these 'partial types' are like implicit static-polymorphism 
interfaces? i.e. they make guarantees about the interface, but don't 
require that the types explicitly derive from them?

Presumably you could use these to specify template constraints as well?

e.g.

int gcd(InputRange!int Range)(Range r) { ... }

which would be equivalent to:

int gcd(Range)(Range r) if (isInputRange!Range) { ... }

Seems like the logical thing to do.


More information about the Digitalmars-d mailing list