Last active
August 2, 2017 13:07
-
-
Save warmist/b9a9fbb274d5cc88d78208df38d27b2f to your computer and use it in GitHub Desktop.
Misc cpp functions
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
template<typename T,long N> | |
constexpr long countof(T(&)[N]){return N;} | |
//TODO: add this -http://stackoverflow.com/a/24881903 | |
//TODO: file embedding lib | |
/* | |
void GetResourceAsString(int nResourceID, CStringA &strResourceString) | |
{ | |
HRSRC hResource = FindResource(NULL, MAKEINTRESOURCE(nResourceID), L"DATA"); | |
HGLOBAL hResHandle = LoadResource(NULL, hResource); | |
const char* lpData = static_cast<char*> ( LockResource(hResHandle) ); | |
strResourceString.SetString(lpData, SizeofResource(NULL, hResource)); | |
FreeResource(hResource); | |
} | |
*/ | |
#define IMPL_BITMASK_ENUM(T) \ | |
inline constexpr T operator&(T x, T y){ return static_cast<T> (static_cast<std::underlying_type<T>::type>(x) & static_cast<std::underlying_type<T>::type>(y));}\ | |
inline constexpr T operator|(T x, T y){ return static_cast<T> (static_cast<std::underlying_type<T>::type>(x) | static_cast<std::underlying_type<T>::type>(y));}\ | |
inline constexpr T operator^(T x, T y){ return static_cast<T> (static_cast<std::underlying_type<T>::type>(x) ^ static_cast<std::underlying_type<T>::type>(y));}\ | |
inline constexpr T operator~(T x){ return static_cast<T> (~static_cast<std::underlying_type<T>::type>(x));}\ | |
inline T & operator&=(T & x, T y){x= x & y;return x;}\ | |
inline T & operator|=(T & x, T y){x= x | y;return x;}\ | |
inline T & operator^=(T & x, T y){x= x ^ y;return x;} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment