src/macros.h

changeset 1013
fa025ba493d8
parent 1010
969b48eddd6b
child 1014
f0a8ecb6a357
--- a/src/macros.h	Wed Nov 18 19:05:22 2015 +0200
+++ b/src/macros.h	Thu Nov 19 00:43:18 2015 +0200
@@ -65,3 +65,27 @@
 		NAME = ENUM::NumValues)
 
 #define ConfigOption(...)
+
+// once-statement
+struct OnceGuard
+{
+	bool triggered;
+	OnceGuard() : triggered (false) {}
+
+	bool pass()
+	{
+		if (triggered)
+		{
+			return false;
+		}
+		else
+		{
+			triggered = true;
+			return true;
+		}
+	}
+};
+
+#define TEE_2(A,B) A ## B
+#define TEE(A,B) TEE_2(A,B)
+#define once static OnceGuard TEE(_once_, __LINE__); if (TEE(_once_, __LINE__).pass())

mercurial