summaryrefslogtreecommitdiffhomepage
path: root/compat/macros.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'compat/macros.hpp')
-rw-r--r--compat/macros.hpp7
1 files changed, 6 insertions, 1 deletions
diff --git a/compat/macros.hpp b/compat/macros.hpp
index 61c49975..0807df4c 100644
--- a/compat/macros.hpp
+++ b/compat/macros.hpp
@@ -44,8 +44,13 @@
// from now only C++
+#include <utility>
+
//#define once_only(...) do { static bool once__ = false; if (!once__) { once__ = true; __VA_ARGS__; } } while(false)
-#define once_only(expr) ([&] { static decltype(auto) ret___1132 = (expr); return ret___1132; }())
+//#define once_only(expr) ([&] { static decltype(auto) ret___1132 = (expr); return (decltype(ret___1132) const&) ret___1132; }())
+
+#define eval_once__2(expr, ident) (([&] { static bool ident = ((expr), true); (void)(ident); }))
+#define eval_once(expr) eval_once__2(expr, PP_CAT(eval_once_init__, __COUNTER__))
#include <type_traits>