Is my previous statement only valid if placement new used a reinterpret_cast on it's implementation? Or if h.storage was reinterpret_cast-ed to a void* when it was passed in? Well, if reinterpret_cast remembered the type, it would know it wasn't what we were trying to cast it to.
Also, instead of a placement_cast, why not write a placed_new<> template (as someone said, offset_cast is only used in this situation): template <typename Storage, typename Object> Object* const placed_new (Storage* const storage) { new (storage) Object; return ...; } // .. support construction with (1, 2, 3, ...) parameters as well "Eric Woodruff" <[EMAIL PROTECTED]> wrote in message aso09f$akc$[EMAIL PROTECTED]">news:aso09f$akc$[EMAIL PROTECTED]... > > "Anthony Williams" <[EMAIL PROTECTED]> wrote in > message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... > > Eric Woodruff writes: > > > "Anthony Williams" <[EMAIL PROTECTED]> wrote in > > > message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... > > > > Thus, given that h.storage is properly aligned, (which is the purpose > of > > > the > > > > other union member), after "new(h.storage) Foo", h.storage contains a > Foo > > > > object. Thus accessing it through a pointer-to-Foo is legal, as Foo > is the > > > > dynamic type of the object. > > > > > > > > > > This is precisely my reasoning why reinterpret_cast<> is _not_ > > > implementation defined. > > > > > > It must be the case that it is equal to the situation of having > > > > > > Foo* -> char */void* -> Foo* if Foo is the dynamic type of the object. > > > > Nowhere do I see a requirement that supports your deductions. Indeed there > are > > very few requirements on reinterpret_cast<>, other than the fact that what > it > > does must be defined by the implementation. For pointers to objects, these > > amount to: > > > > * T1* can be converted to T2* and back again unchanged (unless T2 has > stricter > > alignment requirements). > > Precisely, T1 is Foo in this case as you have already pointed out. This is > simply the identity conversion T1 -> T2 -> T1, which is pretty much the only > thing reinterpret_cast can do portably. > [snip] _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost