
6 Oct
2005
6 Oct
'05
8:14 p.m.
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