2

What does the below mean

template < template < template < class > class, class > class Param >

I never used template <template <X>> kind of syntax

Got it off of another website

template < template < template < class > class, class > class Param >
struct Bogus {


int foo() {
printf("ok\n");;
}
};

Appreciate any light on this syntax. Thank you

Update: Looks like there were some explanations already existing, please refer to Jerry's solution below

Chenna V
  • 10,185
  • 11
  • 77
  • 104

2 Answers2

5

It's called a template template parameter. It's been discussed a number of times before:

Syntax of C++ Template Template Parameters
What are some uses of template template parameters in C++?
Use template template class argument as parameter

etc.

Community
  • 1
  • 1
Jerry Coffin
  • 476,176
  • 80
  • 629
  • 1,111
  • so much stuff in C++, I keep learning and more stuff keeps showing up :D. hope there was a bible. Thanks Jerry – Chenna V Oct 08 '11 at 00:12
3

There are three ontological tiers in C++: values, types and templates.

A template instantiation is a type. An object is of a certain type, and it has a value.

All three sorts of entities can appear as template parameters:

template <int N, typename T, template <typename> C>
{
  C<T> array[N];
};

The parameter are classified, in this order, as "non-type template parameter", "template parameter", and "template template parameter" (I think).

Having template parameters can be very useful, for example if you want to allow something to be parametrized on arbitrary containers (especially with variadic templates!):

template <typename T, template <typename...> Container>
void print(const Container<T> & c)
{ /* ... */ }

Incidentally, when a class template contains members, you have to use the words typename and template, respectively to address them according to their nature (saying nothing means you want to refer to a value):

template <typename T> struct Foo
{
  T value;
  typedef T * pointer;
  template <typename S> struct Nested;
};

// now refer to them as:
Foo<T>::value;
typename Foo<T>::pointer;
template<typename S> Foo<T>::template Nested<S>;
Kerrek SB
  • 464,522
  • 92
  • 875
  • 1,084