Boost logo

Boost :

From: jsiek_at_[hidden]
Date: 2000-06-30 14:03:44

I was a bit disgruntled last night when I found out that
compressed_pair didn't work with g++ :(

The problem is that g++ doesn't really do the empty base

struct foo { };
struct bar : public foo { int x; };
struct yow : public foo { };

sizeof(foo)= 1
sizeof(bar)= 8 (should be 4)
sizeof(yow)= 1

This causes several problems. First boost::is_empty gives the wrong
result for foo. I tried the following workaround which seemed to work
(though someone more familiar with this should make sure it is ok).

template <typename T>
struct empty_helper_t1 : public T
#ifdef __MWERKS__
   empty_helper_t1(); // hh compiler bug workaround
#ifndef __GNUC__
   // g++ only optimizes space when derived class is empty :(
   int i[256];
struct empty_helper_t2 {
#ifndef __GNUC__
  int i[256];

The second problem, of course is that the compressed_pair mechanism
won't reduce the size as it should with g++. I then started to try to
think of alternate ways to implement compressed_pair that would work
with g++.

One idea was to have a specialization of the compressed_pair's
implementation class that is just plain missing the empty class object
(instead of inheriting from it). The problem with this is that if the
empty class does something in its constructor/destructor, then that
something will not happen as it should.

Can anyone think of other alternatives or workarounds?



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