C++14-way to define global constant x
of some type X
is:
struct X { int i; char c; };
template< typename = void >
X const x_impl{1, 'x'};
static X const & x = x_impl<>;
The technique allows us to avoid ODR-violation (due to external linkage of variable templates).
But for function templates there is a handy possibility to omit angle brackets in following cases:
template< typename T >
void f(T) {}
template< typename T = void >
void g() {}
// ...
f< int >(1);
f<>(1);
f(2); // also valid
g<>();
g(); // also valid
Are there any theoretical reasons to deny the possibility to refer to a variable template without template argument list, even if all the (non-type) template parameters have default (values)? It'll be very convenient to be able to define a global constants (say, in header-only library) in a form like following:
template< int = 0 >
A const a{1, 'a'};
and then to be able to refer to a
without any angle brackets.
std::cout << &a << std::endl; // odr-using