| 1 |
/* |
| 2 |
TEST_OUTPUT: |
| 3 |
--- |
| 4 |
fail_compilation/ice12574.d(40): Error: sequence index `2` out of bounds `[0 .. 2]` |
| 5 |
fail_compilation/ice12574.d(53): Error: template instance `ice12574.reduce!("a", "a").reduce!(Tuple!(int, int, int))` error instantiating |
| 6 |
--- |
| 7 |
*/ |
| 8 |
|
| 9 |
struct Tuple(T...) |
| 10 |
{ |
| 11 |
alias Types = T; |
| 12 |
T field; |
| 13 |
alias field this; |
| 14 |
} |
| 15 |
Tuple!A tuple(A...)(A args) { return typeof(return)(args); } |
| 16 |
|
| 17 |
template binaryFun(alias fun) |
| 18 |
{ |
| 19 |
static if (is(typeof(fun) : string)) |
| 20 |
{ |
| 21 |
auto binaryFun(ElementType1, ElementType2)(auto ref ElementType1 __a, auto ref ElementType2 __b) |
| 22 |
{ |
| 23 |
mixin("alias "~"a"~" = __a ;"); |
| 24 |
mixin("alias "~"b"~" = __b ;"); |
| 25 |
return mixin(fun); |
| 26 |
} |
| 27 |
} |
| 28 |
else |
| 29 |
{ |
| 30 |
alias binaryFun = fun; |
| 31 |
} |
| 32 |
} |
| 33 |
|
| 34 |
template reduce(fun...) |
| 35 |
{ |
| 36 |
auto reduce(Seed)(Seed result) |
| 37 |
{ |
| 38 |
foreach (i, Unused; Seed.Types) |
| 39 |
{ |
| 40 |
result[i] = binaryFun!(fun[i])(1, 1); // here |
| 41 |
} |
| 42 |
return result; |
| 43 |
} |
| 44 |
} |
| 45 |
|
| 46 |
int foo(int value) |
| 47 |
{ |
| 48 |
return value; |
| 49 |
} |
| 50 |
|
| 51 |
void main() |
| 52 |
{ |
| 53 |
reduce!("a", "a")(tuple(1, 1, 1)); |
| 54 |
} |