This code looks interesting (maybe this code is also able to spot a bug in DMD,
or it is able to show something I have not fully understood in D). Do you know
if there are interesting ways to compile it?
T outer(T)(T function(in T) pure foo) pure {
pure int inner() {
return foo(5);
On 02/20/2012 02:26 PM, bearophile wrote:
This code looks interesting (maybe this code is also able to spot a bug in DMD,
or it is able to show something I have not fully understood in D). Do you know
if there are interesting ways to compile it?
T outer(T)(T function(in T) pure foo) pure {
Timon Gehr:
T outer(T)(T function(in T) pure foo) pure {
immutable fooTick = foo;
pure int inner() {
return fooTick(5); // line 3
}
return inner();
}
int sqr(in int x) pure {
return x * x;
}
void main() {
assert(outer(sqr) == 25); // line 14
}