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

Maybe consider even more down with typename #27

Closed BengtGustafsson closed 1 year ago

BengtGustafsson commented 1 year ago

This is probably a separate proposal, but I got the idea while considering Colin's middle ground idea on non-disambiguation:

Just as we know in a type alias that the right hand side must be a type and can assume that a dependent name will resolve to a type we could look up the kind of a template's template parameter and parse the template-argument accordingly, assuming that all dependent name have the corresponding kind. This would allow:

template<anykind T> struct S { std::vector<T*> aa; // NOTE: vector of T pointers! };

I find this slightly too magical, as the compiler has to look up the template parameter kind of vector to be able to parse T*. On the other hand compilers are very apt at detecting mismatching template argument kinds at parse time (before instantiation). This said, there is a difference between what the standard requires compilers to be capable of and what they actually do.

There is also the problem of what to do if the template parameter kind is unknown when parsing. Then the standard rules must apply, i.e. that a dependent name is treated as a value, so aa is a failed constant-expression. It could be hard for programmers to understand whether they need to disambiguate T or not to be able to apply the *.