In prior versions of C++, only functions, classes or type aliases could be templated. C++14 now allows the creation of variables that are templated. An example given in the proposal is a variable pi that can be read to get the value of pi for various types (e.g., 3 when read as an integral type; the closest value possible with float, double or long double precision when read as float, double or long double, respectively; etc.).

The usual rules of templates apply to such declarations and definitions, including specialization.

template<typename T>

constexpr T pi = T(3.141592653589793238462643383);

// Usual specialization rules apply:

template<>

constexpr const char* pi<const char*> = "pi";