import std.stdio;
struct A {
static int[string] impl;
static this() {
impl = [
"a": 1,
"b": 2,
];
}
int opApply(scope int delegate(string a, int b) dg) {//实际执行的是这个函数.
foreach (k, v; impl) {
auto r = dg(k, v);//插入闭包.
if (r) return r;
}
return 0;
}
}
void main() {
A a;
foreach (k, v; a) {
writefln("%s -> %s", k, v);
}
}