
"John Maddock" <john@johnmaddock.co.uk> writes:
Well, compressed_pair applies to a pair and compressed_member applies memberwise. In a situation where you have more than two members compressed_member may compact better.
Consider this situation:
struct A {}; struct B {};
struct C : compressed_member<A> , compressed_member<A, 1> , compressed_member<B, 1> , compressed_member<B, 1> { };
Here, each A gets its address but the Bs can share those same addresses. I think applying the optimization memberwise may scale better for arbitrary tuples.
Except that most compilers don't implement the empty-base-optimisation when there is multiple inheritance taking place, in fact for at least one compile (Borland's) this is a serious dis-optimisation, with 8-bytes per base class getting added!
The compressed_pair way would be:
struct C { private: boost::compressed_pair< empty_type1, boost::compressed_pair< empty_type2, non_empty_type> > m_data; };
and of course this way struct C doesn't have any "accidental" base classes, not even private ones.
But then C can't itself be an empty class, IIUC. Am I wrong about that? -- Dave Abrahams Boost Consulting http://www.boost-consulting.com