Doesn't match the <typename ...> pattern in the <typename> pattern is a defect?

Studying this answer , I found that a template that accepts a parameter package will not be accepted by a template that expects a template that has a certain number of parameters.

It seems to me that this is a defect, because if the template can take any number of parameters, it should be able to match a certain number. Is there a language attorney who could explain why this is not allowed?

Here is a simple example:

template <typename...Ts> using pack = void; template <template <typename> class> using accept_template = int; accept_template<pack> value = 0; 

I would not use it in this exact scenario, of course. It will be used to transfer the template to another template that would somehow use the passed template. In my answer that I linked, I said a workaround, but I still feel that this is a defect.

+8
c ++ language-lawyer c ++ 11 c ++ 14
source share
1 answer

This restriction was relaxed as a result of P0522 , which introduced new rules for processing how template templates match template parameters. As a result of the article:

 template<class T, class U = T> class B { /* ... */ }; template <class ... Types> class C { /* ... */ }; template<template<class> class P> class X { /* ... */ }; X<B> xb; // OK, was ill-formed: // default arguments for the parameters of a template argument are ignored X<C> xc; // OK, was ill-formed: // a template parameter pack does not match a template parameter 

Your example will not compile in C ++ 14, but will compile in C ++ 17.

+12
source share

All Articles