Created
February 28, 2016 20:44
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** 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