I have a template class that looks something like this:
template <typename T>
class foo
{
static const T arr[16];
};
The contents of foo<T>::arr
are numerically identical for all types T
that I plan to use. For example, I would initialize it for T = float
and T = double
by placing lines in a source file as follows:
float foo<float>::arr[16] = {1, 2, 3, 4, ...};
double foo<double>::arr[16] = {1, 2, 3, 4, ...};
Is there a way that I can initialize this in one place without having to repeat myself and enumerate all of the types that T
can take on? Note that since the type of each array element is T
, I can't use the trick of deriving foo<T>
from a non-template base class that holds the static array.