On 10/11/2010 10:56 PM, bearophile wrote:
Pelle:

string assertReturnsRangeOf(T)() {
      return "static assert (is(Unqual!(ForeachType!(typeof(return))) == "
          ~ T.stringof ~ "));";
}

auto foo() {
      return map!q{a*a}([1,2,3,4,5]);
      mixin (assertReturnsRangeOf!int);
}

You were probably looking for a more general and, well, good, solution.
This does however convey some intent, and kind of works.

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. :-)

Reply via email to