Boost logo

Boost Users :

From: Gottlob Frege (gottlobfrege_at_[hidden])
Date: 2005-10-06 15:14:00


If for some crazy reason I want/need a uninitialized type T, how do I use
type_with_alignment, etc to make it work?

eg something vaguely like this:

template <typename T>
struct uninitted
{
type_with_alignment<sizeof(T), alignment_of<T>::value_type>::type myT;

void init_later(some_params)
{
new (&myT) T(some_params);
}
};

Does the in-place new work? Is the unitted<T> 'just like' T in terms of
memory, usage within a struct, etc?

struct Foo1
{
Bar bar;
SomeT t;
Foo foo;
};

struct Foo2
{
Bar bar;
uninitted<SomeT> t;
Foo foo;
};

sizeof(Foo1) == sizeof(Foo2)
offsetof(Foo1, t) == offsetof(Foo2, t)
offsetof(Foo1, foo) == offsetof(Foo2, foo)

all true?

Thanks
Tony



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net