1

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
Tomilov Anatoliy
  • 15,657
  • 10
  • 64
  • 169
  • Well, in your example, which `a` are you referring to ? `a` ? `a` ? – Synxis Mar 14 '16 at 12:10
  • @Synxis Of course, similar to the nullary function case (as already illustrated in the question) `a` should refer to `a< ... >` where `...` is defaults (or default values for non-type parameters). – Tomilov Anatoliy Mar 14 '16 at 16:00
  • Well, that makes sense. I guess the best place to have some answer about the rationale is to go on isocpp forums - there a numerous C++ commitee members there – Synxis Mar 14 '16 at 16:10
  • There is a list of forums here: https://isocpp.org/forums. I guess you can post in future proposals... – Synxis Mar 14 '16 at 16:13
  • 1
    Well, there would be ambiguities with `<`, and with variables `<` is a fairly common operation, unlike functions. – T.C. Mar 15 '16 at 09:11

0 Answers0