C ++ template template parameter syntax

I find it difficult to understand the syntax of the parameters of the C ++ template template. I understand why they are useful, as the excellent description here , I just find their syntax is hard to understand. Two examples taken from the above website (there are others):

template <typename T, template <typename> class Cont>
class Stack;

and

template <template <typename,typename> class Cont>
class Wrapper3;

It is clear that a generalization of such declarations is impossible without any understanding of the rationale for this syntax. Remembering is harder and doesn't seem to help much.

Edit: I understand that my attempt to answer the question arose as an observation. What I'm asking for is help on how to interpret the syntax of the Template Template parameter in everyday speech. I can do this with C ++ syntax and all other programming languages ​​that I have learned. However, it’s hard for me to “explain” the syntax of the C ++ template template parameters for myself. I have the book “C ++ Templates: A Complete Guide” by David Vandevoord and Nikolai M. Josuttis, and although this is a good book, it didn’t really help me understand this syntax, which I’m sure many will agree is quirky at best.

+5
source share
2 answers

. :

template <typename> class Cont

,

template <typename T>
class A {
public:
  A(T t) : t_(t) {}
  T get() { return t_; }
private:
  T t_;
};

Stack<int, A> s;
+4

, , .

template <typename T, template <typename> class Cont>
class Stack;

Stack - . T ( , , ..). Cont . , ( ).

template <template <typename,typename> class Cont>
class Wrapper3;

Wrapper3 - Cont. Cont .

, , (template <typename [param1], typename [param2], ...> class Name), , .

, "":

// class template whose parameter must be a class template whose parameter
// must be a class template
template <template <template <typename> class > class C >
struct Wow {};

, ...

+16

All Articles