class A                  { ... }
class NonContainer : A   { ... }
class Container : A      { A[] container; }
class NC1 : NonContainer {}
...
class C1 : Container {}
...

A getO(string info)
{
    switch (info)
    {
        default     : return new NonContainer();
        case "info1": return new C1();
        case "info2": return new NC1();
        case "info3": return new Container();
        case "info4": return new NonContainer();
        ...
    }
}

void foo()
{
    auto o = getO("some information");
    if (is(typeof(o) == Container) { ... }  // Doesn't work.
                                            // Type is always A.
    ...
}

Is there a way to make getO return the most specialized type of the instantiated object in the switch statement to enable this pattern?

Reply via email to