0

I don't see a case where template template parameters would ever be useful, when they could be simply replaced with one template parameter that would work just as well. Referring to my example:

template<template<typename, typename...> typename Cont, typename T, typename... Args>
void Foo(Cont<T, Args...> container)
{
  for (auto i : container)
    std::cout << i << " ";
  std::cout << std::endl;
}

template<typename T>
void Bar(T container)
{
  for (auto i : container)
    std::cout << i << " ";
  std::cout << std::endl;
}

These will function identically, and Bar will work on any container defining an iterator (allocator not needed). Foo however, does the same thing, but is a lot more confusing to write (and more confusing to understand). I don't know if I missed the point on template template parameters, but they really seem useless to me as a single template parameter will deduce the type too, albeit without the other parameters.

Also - should I be using typename or class for the template template parameter?

template<typename> class T

or

template<typename> typename T

Krystian S
  • 1,586
  • 7
  • 23
  • 2
    C++17 allows to use `typename` or `class` there. – Jarod42 Aug 08 '18 at 19:06
  • 3
    An example of something which SHOULD have been a template template parameter is a standard allocator. It would normally be a template itself, instantiated with a specific element being allocated (which for many standard containers is not the data type). However, the lack of support for template template parameters was circumvented with a `rebind` member of a concrete type allocator. – SergeyA Aug 08 '18 at 19:11
  • When you want type, you might even use both method (template template parameters + its parameters vs type). But sometime you might really want only the `template template parameters` (`void foo(C)` or `bar()`). – Jarod42 Aug 08 '18 at 19:19

0 Answers0