class design question (inner classes)

Christian Kamm kamm.incasoftware at shift-at-left-and-remove-this.de
Tue Sep 11 07:44:49 PDT 2007


> If it was possible to instantiate the object "s" at compile time
> (something like
> static const SymmetricGroup s = new SymmetricGroup(3);
> ),
> the above mentioned references would not be needed. But unfortunately, It
> is not possible to instantiate objects at compile time (what's actually
> the reason for this?).

If SymmetricGroup contains only compile time constants, you could do:

struct SymmetricGroup(int degreeIn) {
  const int degree = degreeIn;
}

struct Permutation(Group) {
  alias Permutation!(Group) thistype;
  thistype opMul(ref thistype a) {
    // do something with Group.degree
  }
}

void main() {
  alias SymmetricGroup!(3) s;
  Permutation!(s) a, b, c;
  c = a * b;
}





More information about the Digitalmars-d mailing list