xxxxxxxxxx
import std.stdio;
enum CLOCK_COUNT = 10;
struct Field {
int n = -1;
void opAssign(int a) {
n = a;
writefln("Field.opAssign(%s)", a);
}
}
struct ClockAssign {
Field[CLOCK_COUNT]* clocks;
ref Field opIndex(int a) {
writefln("Register.clock(%s)", a);
return (*clocks)[a];
}
}
struct Register {
Field[CLOCK_COUNT] clocks;
ClockAssign clock() {
return ClockAssign(&clocks);
}
}
void main() {
Register register;
register.clock[1] = 10; // works with "escapes reference" deprecation warning
// register.clock = 10; // error
}