Created
July 3, 2012 17:52
-
-
Save ngbrown/3041364 to your computer and use it in GitHub Desktop.
string starts with
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
#ifndef STRSTARTSWITH_H_ | |
#define STRSTARTSWITH_H_ | |
// From http://blogs.msdn.com/b/the1/archive/2004/05/07/128242.aspx | |
#ifndef __GNUC__ | |
template <typename T, size_t N> | |
char ( &_ArraySizeHelper( T (&array)[N] ))[N]; | |
#define countof(array) (sizeof(_ArraySizeHelper(array))) | |
#else | |
template <class T> | |
class _ArraySizeHelper {}; | |
template <class T, size_t N> | |
class _ArraySizeHelper<T[N]> { | |
public: | |
static const size_t value = N; | |
}; | |
#define countof(x) (_ArraySizeHelper<typeof(x)>::value) | |
#endif // __GNUC__ | |
#define strstartswith(str1, str2) strncmp(str1, str2, countof(str2) - 1) | |
#endif // STRSTARTSWITH_H_ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment