On Friday, 6 April 2018 at 02:20:29 UTC, Kayomn wrote:

Wrong example code, here's the correct example:
switch (queryString(childJson,"type")) {
        case (typeof (Sprite).name):
                child = this.addChild!(Sprite)(childName);


        case (typeof (Camera).name):
                child = this.addChild!(Camera)(childName);


                child = this.addChild!(Node)(childName);


Hi, could you show a bit more implementation details in the C++ version that works? Maybe someone can translate that to the appropriate D version?

The problem seems to be that switching on a runtime value and pattern matching with a compile time value is hard to pull off automatically without some sort of bridge (or of course I've misunderstood this exercise)

So if you had:

class R {
  string type() { return R.stringof; }
class A: R {
  override string type() { return A.stringof; }
class B: R {
  override string type() { return B.stringof; }

string type(T: R)() {
    return T.stringof;

void main() {
  R node = new A;
  final switch (node.type) {
  case type!R: writeln("R"); break;
  case type!A: writeln("A"); break;
  case type!B: writeln("B"); break;

(maybe not a good idea to use stringof though, typeid probably better)


Reply via email to