Skip to content

Instantly share code, notes, and snippets.

@duper
Created February 28, 2016 20:44
Show Gist options
  • Save duper/bbaa75ec8dceff485e10 to your computer and use it in GitHub Desktop.
Save duper/bbaa75ec8dceff485e10 to your computer and use it in GitHub Desktop.
Interesting code from include/anope.h of anope-2.0.3 regarding the optimization of ADT parameterization
/** Casts to be used instead of dynamic_cast, this uses dynamic_cast
* for debug builds and static_cast on releass builds
* to speed up the program because dynamic_cast relies on RTTI.
*/
#ifdef DEBUG_BUILD
# include <typeinfo>
template<typename T, typename O> inline T anope_dynamic_static_cast(O ptr)
{
T ret = dynamic_cast<T>(ptr);
if (ptr != NULL && ret == NULL)
throw CoreException(Anope::string("anope_dynamic_static_cast<") + typeid(T).name() + ">(" + typeid(O).name() + ") fail");
return ret;
}
#else
template<typename T, typename O> inline T anope_dynamic_static_cast(O ptr)
{
return static_cast<T>(ptr);
}
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment