diff options
author | Bardur Arantsson <bardur@scientician.net> | 2016-03-29 20:32:55 +0200 |
---|---|---|
committer | Bardur Arantsson <bardur@scientician.net> | 2016-03-29 20:32:55 +0200 |
commit | c8df88d8c61197d8f019efa0ba373ed14a28d914 (patch) | |
tree | 75335e7c9d0784ec4fa267c1a85f42e68100484c /src/include/tome/pp/global_constexpr.hpp | |
parent | 1a8a922f380a6401972f57beae602f3e8eca37e7 (diff) |
Introduce new way of handling flags
Diffstat (limited to 'src/include/tome/pp/global_constexpr.hpp')
-rw-r--r-- | src/include/tome/pp/global_constexpr.hpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/include/tome/pp/global_constexpr.hpp b/src/include/tome/pp/global_constexpr.hpp new file mode 100644 index 00000000..83168c59 --- /dev/null +++ b/src/include/tome/pp/global_constexpr.hpp @@ -0,0 +1,21 @@ +#pragma once + +/** + * Macro for declaring a global constexpr variable without + * violating the ODR and without running into the SIOF. + * + * Shamelessly cribbed from http://stackoverflow.com/a/20374473 + */ +#define PP_GLOBAL_CONSTEXPR_CONST(type, var, value) \ +namespace global_constexpr { namespace var { \ +template<class = void> \ +struct wrapper \ +{ \ + static constexpr type var = value; \ +}; \ +template<class T> \ +constexpr type wrapper<T>::var; \ +} } \ +namespace { \ +auto const& var = global_constexpr::var::wrapper<>::var; \ +} |