summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2019-03-22 04:28:00 +0100
committerStanislaw Halik <sthalik@misaki.pl>2019-03-28 08:58:40 +0100
commite3e8caf61bbc22c3b278ce8bd36501b73806d524 (patch)
treeac24885c76082486e1fbd12ef5f525ea5d566d24
parent01b80e4f56cc9f5120a9a34690e6f593006e5585 (diff)
actually expand __COUNTER__
-rw-r--r--compat/macros1.h3
-rw-r--r--migration/migration.hpp15
-rw-r--r--options/metatype.cpp15
-rw-r--r--video-opencv/camera-impl.cpp0
-rw-r--r--video/camera.hpp19
5 files changed, 23 insertions, 29 deletions
diff --git a/compat/macros1.h b/compat/macros1.h
index 5e3129d5..f6b05f0f 100644
--- a/compat/macros1.h
+++ b/compat/macros1.h
@@ -42,6 +42,7 @@
#ifdef __cplusplus
# define progn(...) ([&]() -> decltype(auto) { __VA_ARGS__ }())
+# define eval_once2(expr, ctr) eval_once3(expr, ctr)
+# define eval_once3(expr, ctr) ([&] { [[maybe_unused]] static const char init_ ## ctr = ((void)(expr), 0); }())
# define eval_once(expr) eval_once2(expr, __COUNTER__)
-# define eval_once2(expr, ctr) ([&] { [[maybe_unused]] static auto init ## ctr = (((void)(expr)), 0); }())
#endif
diff --git a/migration/migration.hpp b/migration/migration.hpp
index 2c1fee5b..a3035247 100644
--- a/migration/migration.hpp
+++ b/migration/migration.hpp
@@ -57,19 +57,14 @@ namespace detail {
};
}
-#ifndef __COUNTER__
-# error "oops, need __COUNTER__ extension for preprocessor"
-#endif
+#define OPENTRACK_MIGRATION3(type, ctr) \
+ static const char init_##ctr = (::migrations::detail::registrator<type>{}, 0);
-#define MIGRATE_EXPAND2(x) x
-#define MIGRATE_EXPAND1(x) MIGRATE_EXPAND2(x)
-#define MIGRATE_EXPANDED2(type, ctr) \
- static ::migrations::detail::registrator<type> opentrack_migration_registrator_ ## ctr
-#define MIGRATE_EXPANDED1(type, ctr) \
- MIGRATE_EXPANDED2(type, ctr)
+#define OPENTRACK_MIGRATION2(type, ctr) \
+ OPENTRACK_MIGRATION3(type, ctr)
#define OPENTRACK_MIGRATION(type) \
- MIGRATE_EXPANDED1(type, MIGRATE_EXPAND1(__COUNTER__))
+ OPENTRACK_MIGRATION2(type, __COUNTER__)
struct migration
{
diff --git a/options/metatype.cpp b/options/metatype.cpp
index 64df3b1a..7962b81b 100644
--- a/options/metatype.cpp
+++ b/options/metatype.cpp
@@ -12,15 +12,16 @@ void declare_metatype_for_type(const char* str)
} // ns options::detail
-#define OPENTRACK_DEFINE_METATYPE2(t, ctr) \
- namespace { /* NOLINT(cert-dcl59-cpp) */ \
- [[maybe_unused]] \
- static const char ctr = /* NOLINT(misc-definitions-in-headers) */ \
- (::options::detail::declare_metatype_for_type<t>(#t), 0); \
- } // anon ns
+#define OPENTRACK_DEFINE_METATYPE3(t, ctr) \
+ static \
+ const char init_##ctr = /* NOLINT(misc-definitions-in-headers) */ \
+ (::options::detail::declare_metatype_for_type<t>(#t), 0); \
+
+#define OPENTRACK_DEFINE_METATYPE2(t, ctr) \
+ OPENTRACK_DEFINE_METATYPE3(t, ctr)
#define OPENTRACK_DEFINE_METATYPE(t) \
- OPENTRACK_DEFINE_METATYPE2(t, PP_CAT(kipple_, __COUNTER__))
+ OPENTRACK_DEFINE_METATYPE2(t, __COUNTER__)
#define OPENTRACK_METATYPE_(x) OPENTRACK_DEFINE_METATYPE(x)
#include "metatype.hpp"
diff --git a/video-opencv/camera-impl.cpp b/video-opencv/camera-impl.cpp
deleted file mode 100644
index e69de29b..00000000
--- a/video-opencv/camera-impl.cpp
+++ /dev/null
diff --git a/video/camera.hpp b/video/camera.hpp
index 21f4f916..4ad8417c 100644
--- a/video/camera.hpp
+++ b/video/camera.hpp
@@ -67,17 +67,14 @@ void register_camera(std::unique_ptr<impl::camera_> metadata);
} // ns video::impl
-#define OTR_REGISTER_CAMERA2(type, ctr) \
- namespace { \
- struct init_##ctr \
- { \
- static char fuzz; \
- }; \
- char init_##ctr :: fuzz = \
- (::video::impl::register_camera(std::make_unique<type>()), 0); \
- } // anon ns
-
-#define OTR_REGISTER_CAMERA(type) \
+#define OTR_REGISTER_CAMERA3(type, ctr) \
+ static const char init_ ## ctr = \
+ (::video::impl::register_camera(std::make_unique<type>()), 0);
+
+#define OTR_REGISTER_CAMERA2(type, ctr) \
+ OTR_REGISTER_CAMERA3(type, ctr)
+
+#define OTR_REGISTER_CAMERA(type) \
OTR_REGISTER_CAMERA2(type, __COUNTER__)
namespace video