From 73d7705416a29ab75789cfe5d37ab5720b00d98d Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Tue, 22 Oct 2013 01:02:49 +0200 Subject: [PATCH] Add some templates for cleaner array iteration. --- Source/cmStandardIncludes.h | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/Source/cmStandardIncludes.h b/Source/cmStandardIncludes.h index d09b3047d..6c7714481 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 +const T* cmArrayBegin(const T (&a)[N]) { return a; } +template +const T* cmArrayEnd(const T (&a)[N]) { return a + N; } +template +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