src/macros.h

changeset 847
274a7fac44fc
parent 844
11587d419d2f
child 855
e16f1587ef44
--- a/src/macros.h	Sun Jul 20 05:01:51 2014 +0300
+++ b/src/macros.h	Sat Jul 26 03:43:37 2014 +0300
@@ -115,6 +115,17 @@
 	inline T operator++ (T& a, int) { T result = a; a = (T) ((int) a + 1); return result; } \
 	inline T operator-- (T& a, int) { T result = a; a = (T) ((int) a - 1); return result; }
 
+#define FOR_ENUM_NAME_HELPER(LINE) enum_iterator_ ## LINE
+#define FOR_ENUM_NAME(LINE) FOR_ENUM_NAME_HELPER(LINE)
+
+#define for_enum(ENUM, NAME) \
+	for (std::underlying_type<ENUM>::type FOR_ENUM_NAME (__LINE__) = \
+		std::underlying_type<ENUM>::type (ENUM::FirstValue); \
+		FOR_ENUM_NAME (__LINE__) < std::underlying_type<ENUM>::type (ENUM::NumValues); \
+		++FOR_ENUM_NAME (__LINE__)) \
+	for (ENUM NAME = ENUM (FOR_ENUM_NAME (__LINE__)); NAME != ENUM::NumValues; \
+		NAME = ENUM::NumValues)
+
 // =============================================================================
 #ifdef IN_IDE_PARSER // KDevelop workarounds:
 # error IN_IDE_PARSER is defined (this code is only for KDevelop workarounds)
@@ -130,4 +141,4 @@
 
 static const char* __func__ = ""; // Current function name
 typedef void FILE; // :|
-#endif // IN_IDE_PARSER
\ No newline at end of file
+#endif // IN_IDE_PARSER

mercurial