| 1 |
template binaryFun(alias fun) |
| 2 |
{ |
| 3 |
static if (is(typeof(fun) : string)) |
| 4 |
{ |
| 5 |
auto binaryFun(E1, E2)(E1 a, E2 b) |
| 6 |
{ |
| 7 |
return mixin(fun); |
| 8 |
} |
| 9 |
} |
| 10 |
else |
| 11 |
{ |
| 12 |
alias binaryFun = fun; |
| 13 |
} |
| 14 |
} |
| 15 |
|
| 16 |
class Foo(int n, alias greater = "a > b") |
| 17 |
{ |
| 18 |
private alias binaryFun!(greater) compare; |
| 19 |
|
| 20 |
public this() |
| 21 |
{ |
| 22 |
//assert(compare(2, 1)); |
| 23 |
// 'compare' -> FuncExp |
| 24 |
|
| 25 |
assert(this.compare(2, 1)); |
| 26 |
// old: 'this.compare' -> DotVarExp (e1: ThisExp, var: FuncLiteralDeclaration) |
| 27 |
// new: 'this.compare' -> CommaExp (e1: ThisExp, e2: FuncExp) |
| 28 |
|
| 29 |
// Then, in both cases lambda->toObjFile() will run via FuncExp::toElem(). |
| 30 |
} |
| 31 |
} |
| 32 |
|
| 33 |
void main() |
| 34 |
{ |
| 35 |
// OK |
| 36 |
auto foo1 = new Foo!(1, "a > b"); |
| 37 |
auto foo2 = new Foo!(2, (a, b) => a > b); |
| 38 |
auto foo3 = new Foo!(3, delegate(a, b){ return a > b; }); |
| 39 |
|
| 40 |
// OK <- NG |
| 41 |
auto foo4 = new Foo!(4, (int a, int b) => a > b); |
| 42 |
auto foo5 = new Foo!(5, function(int a, int b){ return a > b; }); |
| 43 |
auto foo6 = new Foo!(6, delegate(int a, int b){ return a > b; }); |
| 44 |
} |