Eric Woodruff writes:
 > Is my previous statement 

 > > 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.

 >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.

The point is, you don't have a Foo* in the first place, you only have a char*,
unless you saved the result of placement new somewhere, in which case you
don't have a problem.

The argument that you can get to a Foo* given just a char/void * to the raw
storage using reinterpret_cast<> relies on the equivalence of
reinterpret_cast<void*> and static_cast<void*>, which I don't think is
justified.
 
 > 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

Because that gets you nothing vs just using placement new directly.
 
 > "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

Anthony
-- 
Anthony Williams
Senior Software Engineer, Beran Instruments Ltd.
Remove NOSPAM when replying, for timely response.

_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

Reply via email to