Boost logo

Boost :

From: Robert Kawulak (kawulak_at_[hidden])
Date: 2005-10-12 10:52:56

Hi all,

I've got the following "moral dilemma": there's an easy way to let the
constrained type have dynamic bounds when needed. I.e. with the current
policies nothing changes, but also a new bounds-specifying policy could be
added that lets change the bounds at run-time. The trick is that the
policies would have to be inherited by the constrained_type template. And
here the problem begins - with some compilers inheriting from classes with
no members doesn't change the sizeof of object, while with others it does.
For instance:

struct e { };

struct f : public e { };

// A class inherited from empty base classes, with a char member
struct g : public f {
  char c;

// Same as g but not inherited
struct h {
  char c;

The sizeof for e, f, g and h is, respectively:
with gcc & MSVC: 1, 1, 1, 1
DMC: 1, 1, 2, 1
Borland: 8, 8, 16, 1

So the point is that when the policies are inherited, then users may have to
pay for this with extra size of constrained objects, even when the policy
classes doesn't contain any non-static members (which is the case with the
current policies). Is there any workaround for this (IOW is there any way to
make inheritance of empty classes not make sizeof grow)? Of course
composition instead of inheritance is a no-go, because it always makes
sizeof bigger. Is it worth to add this functionality to the constrained type
even though with some compilers its size will grow?


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