summaryrefslogtreecommitdiff
path: root/src/include/tome/pp/global_constexpr.hpp
blob: 83168c59f3c23be93be00cbb15f510648856f86f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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;                 \
}