Created
January 24, 2017 10:00
-
-
Save iboB/dec00b9468db8ea4962e051828a28744 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
template <typename T> | |
struct fast_static | |
{ | |
// call globally to ensure the constructor is called | |
static T& slow_get() | |
{ | |
static T t; | |
return t; | |
} | |
static T* const _fast_var; | |
// never call globally! | |
// call after entering main to skip sync of local static | |
static T& fast_get() | |
{ | |
return *_fast_var; | |
} | |
}; | |
template <typename T> | |
T* const fast_static<T>::_fast_var = &fast_static<T>::slow_get(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment