I'm generating an constexpr std::array
inside of a constexpr
class, but I only want one instance of that class over all of the project where it is used.
I had originally made it a global, but then I found out that these globals are duplicated if I iterate over the array in multiple translation units. I then attempted to use a constexpr
function, but I can't have a static
inside of such a function. I'm using c++14, so I can't use an inline constexpr
variable. An extern constexpr
variable doesn't make sense because if you separate the declaration from the definition, then how can the constexpr
values be dealt with in a compile time rather than a runtime manner when only one item is needed?
Are there any other options?
EDIT: See https://godbolt.org/z/5PcboYov4
Please remember that I'm not defining a regular variable. I'm defining a constexpr
variable. The difference is IMPORTANT. It is being used in both non-constexpr
and constexpr
contexts.