|
Boost : |
From: Eric Woodruff (Eric.Woodruff_at_[hidden])
Date: 2002-12-08 11:51:14
I don't think that anyone is going to find a new quote from the standard
that will end the discussion on reinterpret_cast. Even and email from Bjarne
okayed by three major platform compiler developers probably wouldn't suffice
anymore.
I had pointed out that instead of using any cast, one can just use a
placed_new<> template that returns the correct object. I guess that isn't
always useful since there are other needs besides creation (unless the
object in h.storage was self-deleting and never accessed through h.storage
again).
Here's a question: Since h.storage is _meant_ to be accessed by those that
do not know the type of the object inside, shouldn't it have been designed
as a void* in the first place? This has two benefits (and I've recently had
the epiphany of why void* is ok):
1) A void* makes it more convenient for the user of the class to access the
object via static_cast. static_cast is just as dangerous as reinterpret_cast
when you have a void* typelessObject;
2) A void* abstracts out the manor in which h.storage was allocated, which
hides more implementation details.
Unfortunatly, it probably takes more memory and requires use of the heap.
Can someone tell me the destruction semantics in this scenerio? How does the
object in h.storage get destroyed? It seems like the object that used the
placed new cannot have its destructor called.
Anyhow, that was just one example given to work with. I think that with a
combination of static_casts there is no run-time overhead, so what wrong
with just using dangerous_cast? It could maybe use a better name.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk