On 2013-08-11 21:08, Simen Kjaeraas wrote:

If you're looking for a no-overhead solution, then this might not be
good enough. I'm surprised that a virtual function call is fine,
though.

How about this:

interface I
{
    size_t size (this T) ()
    {
        return __traits(classInstanceSize, T);
    }
}

class A : I
{
}

class B : I
{
    int a;
}

void main ()
{
    auto a = new A;
    auto b = new B;

    assert(a.size == 24);
    assert(b.size == 32);
}

--
/Jacob Carlborg

Reply via email to