Due to prior design choices, I have the following setup:

enum K { A, B }

mixin template Magic()
{
  mixin(`alias Other = ` ~ magic() ~ `!(K.B);`);
}

struct S(K k) if (k == K.B) {}
struct S(K k)
  if (k == K.A)
{
  mixin Magic; // magic() returns "S"
}

struct T(K k) if (k == K.B) {}
struct T(K k)
  if (k == K.A)
{
  mixin Magic; // magic() returns "T"
}

alias A(alias T) = T!(K.A);

void main()
{
  A!S a;
}


Is there any possible way I can write magic() so that the above code works as intended? n.b. it must be able to go through the alias A.

For what it's worth, I'm trying to define "Other" for the generic struct parameterised with k == K.A such that I can instantiate it's sister struct parameterised by K.B, e.g.

A!S a; // type is S!(K.A)
alias U = a.Other;
U b; // type is S!(K.B)

Reply via email to