atomgalaxy / isocpp-universal-template-param

We propose a way to spell a universal template parameter kind. This would allow for a generic apply and other higher-order template metafunctions, and certain typetraits.
https://atomgalaxy.github.io/isocpp-universal-template-param/d1985r0.pdf
2 stars 2 forks source link

Add discussion on template parameter default arguments. #45

Open BengtGustafsson opened 2 years ago

BengtGustafsson commented 2 years ago

In P1985R3 we propose that dependent template-arguments do not need to be disambiguated and that all kind checking is deferred to instantiation time. I think we have to write something to the effect that the same thing applies to default arguments in template parameter lists. Unfortunately the grammar is not expressed like:

template-parameter:
     template-parameter-head
     template-parameter-head = template-argument

If it were it would be easy to state that template-argument never needs to be disambiguated using typename or template. But instead template-parameter is first split into the three different kinds and then each of those kinds is allowed to have a default of the corresponding kind. Here is an example of what I'm talking about [https://godbolt.org/z/PYzT8cs4q]()


template<typename T> struct S {
     template<typename X = T::name> void f();
     template<auto X = T::name> void g();
     template<template<typename...> class X = T::name> void h();
     template<template auto X = T::name> void u();
};

Here the T::name in h results in a parsing error requiring it to be disambiguated as template although it is quite obvious that it must be a template. f was also in error before down with typename.

I think that to mirror the new deferred kind check of template-argument the standard must also mandate that no kind check is to be done at parsing time for default arguments. Wordingwise this could be done by rearranging the grammar to something like what I indicated above but I think it would be easier to just add some text to the template parameter section enforcing the deferred checking.