Each problem can be solved by adding another layer of indirection (except for too many indirect ones):
// no a[] here. template <typename T> struct ConstArray; template <> struct ConstArray<int> { static constexpr int a[] = {1, 2, 3, 4, 5}; int operator[](int idx) const { return a[idx]; } }; template <typename T> class A { static constexpr ConstArray<T> a; };
Barry source share