
Sebastian Redl wrote:
That approach seems like bloat. Couldn't polymorphic_cast and polymorphic_downcast be overloaded?
How is that less bloat?
Having all of any_cast (dynamic_cast which always throws on error), any_unsafe_cast (static_cast), any_downcast (static_cast with debug checks) and finally any_test_cast (dynamic cast that can return null) doesn't seem like bloat to you? any_test_cast and any_unsafe_cast should be all you need to build all of the rest *outside* of the class. I would even like it better if 'any' directly overloaded dynamic_cast and static_cast in some way. And why would you call the cast any->concrete type
a polymorphic cast?
polymorphic_cast is really the same thing as a dynamic_cast, except it always throws even with dealing with pointers. polymorphic_downcast is really just a static_cast with some checking in debug mode. They should IMHO be implemented in terms of dynamic_pointer_cast and static_pointer_cast, since dynamic_cast and static_cast are not overloadable. Then any type that wants to implement safe and unsafe casts should overload *_pointer_cast instead of always reinventing names and funtions. And you get the fancy polymorphic casts for free, since they're written generically. The names were probably badly chosen, since there is nothing inherently polymorphic, but they're here now. I prefer having a single overloadable operator that always has the same meaning than a lot of class-specific utilities which do not cover everything, which is interface bloat to me.