Boost logo

Boost :

Subject: Re: [boost] [Operators] empty_base should be untemplated?
From: Andrew Ho (helloworld922_at_[hidden])
Date: 2013-07-20 14:03:13

> It's templated so that multiple inheritance doesn't kill the empty base
> optimization.

With which compiler? I tests using gcc 4.8.1 and as far as I can tell
there's no difference between using templated empty_base vs. untemplated
empty_base. Even some times with templated empty_base gcc 4.8.1 would not do
empty base class optimization using enough multiple inheritance.

VS2012 doesn't appear to do empty base class optimization for multiple
inheritance at all, so templated/untemplated also makes no difference here.

In addition to this, I thought empty_base is there to transform the
operation into single inheritance anyways. VS2012 and gcc 4.8.1 both seem to
be able to handle single inheritance optimizations fine even if empty_base
isn't templated.

// can replace with plain old operators and run the same test.
// I'm just using operators2 because it's much easier for me to test
templated/untemplated empty_base
class MyClass : public boost::operators2::addable< MyClass >
        ,public boost::operators2::subtractable< MyClass >
        ,public boost::operators2::multipliable< MyClass >
        ,public boost::operators2::dividable< MyClass >
        ,public boost::operators2::xorable< MyClass > // comment out to drop
size back to sizeof(int) instead of 8
    // commented: gcc fails to perform empty base class optimizations,
sizeof(MyA) = 5
    // uncommented: gcc appears to work and sizeof(MyA) = sizeof(int)
    int val;

    // ... OP= operators omitted for clarity

Boost list run by bdawes at, gregod at, cpdaniel at, john at