Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Template argument for template template parameter must be a class template or type alias template"

template<typename... TArgs> struct List { };
template<template<typename...> class> struct ListHelper;
template<typename T, typename... TArgs> struct ListHelper<List<T, TArgs...>> { };
                                                          ^
   /*Error: Template argument for template template parameter 
             must be a class template or type alias template*/

What's wrong? I'm using clang++ SVN.

like image 963
Vittorio Romeo Avatar asked Jan 10 '14 15:01

Vittorio Romeo


2 Answers

A template template parameter expects the template, not an instantiation of it. This:

template<typename T, typename... TArgs> struct ListHelper<List> { };
//                               only the template itself ^^^^

If you want to pass List<T,TArgs...>, which is a class, you'd need

template<typename T> struct ListHelper;
like image 55
Daniel Frey Avatar answered Nov 07 '22 07:11

Daniel Frey


You have a template template parameter. You must pass a template as its argument. You instead pass a template instantiation as its argument - which is a concrete class, not a template (all its parameters are bound).

Consider:

template <template<typename> typename X>
class WantsTemplate {};

template <typename>
class ATemplate {};

WantsTemplate<ATemplate> wt1;  // OK
WantsTemplate<ATemplate<int> > wt2;  // not OK
like image 20
Igor Tandetnik Avatar answered Nov 07 '22 09:11

Igor Tandetnik