Static cast template
renezwanenburg at gmail.com
Mon Feb 20 05:37:46 PST 2012
A part of the project I'm currently working on relies heavily on
messages being sent between objects. There's some sort of
container object which receives the messages, and notifies any
listeners registered to it. We can't send the messages to the
final recipients directly because the sender doesn't know about
the receivers existence and vice versa.
There are many types of messages, but they all implement a
Message interface. The messageListeners cast the Message to some
ConcreteMessage, but the casting is starting to take a
significant percentage of execution time. Due to the way
MessageListeners are registered, we can be sure a MessageListener
only receives the type of messages it's interested in, so the
cast will never fail.
I'm looking for a static_cast construct, which will be checked
during debug, but in release mode it should minimize overhead by
simply adding the interface offset to the pointer. I've tried to
make use off Type.classinfo's interfaces member, but for some
reason a Type's classinfo isn't available at compile time.
So my question comes down to: does anyone know of a way to get
static_cast behavior for upcasts?
More information about the Digitalmars-d