Boost logo

Boost :

From: scleary_at_[hidden]
Date: 1999-11-19 08:51:37

> Howard Hinnant and Greg Colvin have suggested we include Nathan
> Myer's empty base optimization in boost/utility.hpp. Seems quite
> useful to me, too.
> If you are not familiar with this optimization, check out
> Greg suggested sticking with Nathat's code (except for changing the
> name from BaseOpt, to match Boost practice):
> template <typename Base, typename Member>
> struct base_opt : Base {
> Member m;
> base_opt(Base const& b, Member const& m)
> : Base(b), m(m) {}
> };
> My preference would be for more descriptive names, like
> "empty_base_optimization" and "member".
> Anyone out there care to write some brief documentation? Nathan?

I have found a slightly different form to be useful in my programming. I
originally used Nathan's code, but added typedef's for the template
parameters, the capability of letting Member be a reference type, and a
specialization for swap (if Member has specialized swap for efficiency, that
specialization is lost in the original, even if Base is empty). Lastly, for
convenience, I added three additional constructors. I chose to use the name

I'm including the code I use below, and the docs that I made for it for my
personal use. These docs may serve as a useful starting point; feel free to
use the docs or code in any way you see fit.

One thing I know aren't in my docs are requirements for Base and Member.


P.S. All of the code changes mentioned above (in the first paragraph) I
would recommend incorporating, except possibly the additional constructors.
I have used each of them at least once.

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