3

The following is an excerpt of this cppreference page about variable template

When used at class scope, variable template declares a static data member template.

using namespace std::literals;
struct matrix_constants
{
    template<class T>
    using pauli = hermitian_matrix<T, 2>; // alias template

    template<class T> // static data member template
    static constexpr pauli<T> sigma1 = { { 0, 1 }, { 1, 0 } }; 

    template<class T>
    static constexpr pauli<T> sigma2 = { { 0, -1i }, { 1i, 0 } };

   template<class T>
   static constexpr pauli<T> sigma3 = { { 1, 0 }, { 0, -1 } };
};

The C++ Standard (N4140) says the following in paragraph §14.1 (1.4):

A variable template at class scope is a static data member template.

Thus, it seems to me the declarations in the link above don't need the storage-class-specifier static. Am I correct?

P.S.: I've just started my investigation on templates.

John Kalane
  • 1,163
  • 8
  • 17
  • Are you sure you really want to start your *investigation on templates* with variable templates? May be with something more straightforward? – SergeyA Apr 08 '16 at 20:14
  • @SergeyA I know the Standard is not the best place to study C++, but for now, that's what I'm doing, i.e., I'm following the Standard. – John Kalane Apr 08 '16 at 20:16
  • @Barry But [C++0z](http://eel.is/c++draft/temp#1) still didn't correct the example shown above. – John Kalane Apr 08 '16 at 21:00
  • @JohnKalane Yes, the example is unfortunately incorrect still (see Richard Smith's comment in linked question) – Barry Apr 08 '16 at 21:04

1 Answers1

1

While I still do not think that you've choosen the right course to study templates, I am going to answer direct question.

The wording of Standard (and cppreference) mean that template variables should be defined as static when they are class members. It is a requirement for the developer.

SergeyA
  • 61,605
  • 5
  • 78
  • 137