On 10/04/2010 01:33 PM, bearophile wrote:
Daniel Murphy:
Maybe typeof(return) is what you're looking for? *
auto foo()
{
return map!("a * a")([1, 2, 3, 4]);
static assert(is(Unqual!(ForeachType!(typeof(return))) == int));
}
* Not tested, I don't know if it works like this at all.
That works, thank you. Yes, I am looking for syntax sugar for that code.
Bye,
bearophile
You can hack it with a string mixin :-)
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.