On Sunday, 19 February 2017 at 07:52:13 UTC, Max Samukha wrote:
class A {
    this(T = this)() {
        static assert(is(T == B));
    }
}

class B {
}

auto b = new B;

Here, T becomes A, which may be reasonable but is completely useless. Is there a way to obtain the type of the class (or class instance reference) the method is called on?

Not at compile time:

class A
{
    this()
    {
        assert(typeid(this) == typeid(B));
    }
}

class B : A
{
}

auto b = new B;


Reply via email to