diff options
author | Stephen Kelly <steveire@gmail.com> | 2013-10-21 23:02:49 (GMT) |
---|---|---|
committer | Stephen Kelly <steveire@gmail.com> | 2013-10-22 08:45:23 (GMT) |
commit | 73d7705416a29ab75789cfe5d37ab5720b00d98d (patch) | |
tree | b25d41381845f003de30319a3e93d7eb322eb5fd /Source/cmStandardIncludes.h | |
parent | bf02e750796c6b42b0e9d39ba322cd5191489a0e (diff) | |
download | CMake-73d7705416a29ab75789cfe5d37ab5720b00d98d.zip CMake-73d7705416a29ab75789cfe5d37ab5720b00d98d.tar.gz CMake-73d7705416a29ab75789cfe5d37ab5720b00d98d.tar.bz2 |
Add some templates for cleaner array iteration.
Diffstat (limited to 'Source/cmStandardIncludes.h')
-rw-r--r-- | Source/cmStandardIncludes.h | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/Source/cmStandardIncludes.h b/Source/cmStandardIncludes.h index d09b304..6c77144 100644 --- a/Source/cmStandardIncludes.h +++ b/Source/cmStandardIncludes.h @@ -377,6 +377,34 @@ static thisClass* SafeDownCast(cmObject *c) \ return 0;\ } +#if defined(_MSC_VER) && _MSC_VER < 1300 +#define cmArrayBegin(a) a +#define cmArraySize(a) (sizeof(a)/sizeof(*a)) +#define cmArrayEnd(a) a + cmArraySize(a) + +#else + +template<typename T, size_t N> +const T* cmArrayBegin(const T (&a)[N]) { return a; } +template<typename T, size_t N> +const T* cmArrayEnd(const T (&a)[N]) { return a + N; } +template<typename T, size_t N> +size_t cmArraySize(const T (&)[N]) { return N; } + +#endif + +struct cmStrCmp { + cmStrCmp(const char *test) : m_test(test) {} + cmStrCmp(std::string &test) : m_test(test.c_str()) {} + + bool operator()(const char * input) + { + return strcmp(input, m_test) == 0; + } + +private: + const char *m_test; +}; #endif |