Something like this?

    struct S {
       static int[] a_;
       static float[] b_;
       const size_t idx;
       @property ref int   a() { return a_[idx]; }
       @property ref float b() { return b_[idx]; }
       void opAssign(const S other) {
           a_[idx] = a_[other.idx];
           b_[idx] = b_[other.idx];
       }
       // opSliceAssign() ...
    }

    // ... initialize S.a_ and S.b_ here ...
    auto s = S(200); // 200th entry
    writefln("a = %s, b = %s", s.a, s.b);

You can then simply iterate over S.a_ directly. With some UDA and mixin template magic, the accessors can be generated automatically.

Of course, depending on what you're actually trying to do with it, other abstractions may be more useful to support your typical access patterns.

Reply via email to