| 1 |
module imports.c11447; |
| 2 |
template map(fun...) |
| 3 |
{ |
| 4 |
auto map(Range)(Range r) |
| 5 |
{ |
| 6 |
return MapResult!(fun, Range)(r); |
| 7 |
} |
| 8 |
} |
| 9 |
private struct MapResult(alias fun, R) |
| 10 |
{ |
| 11 |
R _input; |
| 12 |
this(R input) { _input = input; } |
| 13 |
@property bool empty() { return _input.length == 0; } |
| 14 |
@property auto ref front() { return fun(_input[0]); } |
| 15 |
void popFront() { _input = _input[1..$]; } |
| 16 |
} |
| 17 |
|
| 18 |
class A {} |
| 19 |
|
| 20 |
struct TemplateInstancier |
| 21 |
{ |
| 22 |
auto instanciateFromResolvedArgs(A a) |
| 23 |
{ |
| 24 |
auto bs = [B(a)]; |
| 25 |
|
| 26 |
static A gladeulfeurah; |
| 27 |
gladeulfeurah = a; |
| 28 |
|
| 29 |
auto r = bs.map!( |
| 30 |
b => b.apply!( |
| 31 |
function string() { assert(0); }, |
| 32 |
delegate string(i) { |
| 33 |
assert(a is gladeulfeurah, "tagazok"); |
| 34 |
return ""; |
| 35 |
} |
| 36 |
) |
| 37 |
); |
| 38 |
|
| 39 |
foreach (e; r) {} |
| 40 |
} |
| 41 |
} |
| 42 |
|
| 43 |
enum Tag { Undefined, A, } |
| 44 |
|
| 45 |
struct B |
| 46 |
{ |
| 47 |
A a; |
| 48 |
Tag tag; |
| 49 |
|
| 50 |
this(A a) |
| 51 |
{ |
| 52 |
tag = Tag.A; |
| 53 |
this.a = a; |
| 54 |
} |
| 55 |
} |
| 56 |
|
| 57 |
auto apply(alias undefinedHandler, alias handler)(B b) |
| 58 |
{ |
| 59 |
final switch(b.tag) with(Tag) |
| 60 |
{ |
| 61 |
case Undefined : |
| 62 |
return undefinedHandler(); |
| 63 |
|
| 64 |
case A : |
| 65 |
return handler(b.a); |
| 66 |
} |
| 67 |
} |