0
template <typename... T>
struct Tuple { };

template<
            typename T, 
            typename... Rest    // Template parameter pack
        >
class Tuple<T, Rest...> {      // Class parameter pack [1]
    T first;
    Tuple<Rest...> rest;        // Parameter pack expansion
    Tuple(const T& f, const Rest& ... r)
        : first(f)
        , rest(r...) {
    }
};

I am having a hard time understanding why we have angular brackets after class name in class Tuple<T, Rest...> What is it accomplishing? I am new to variadic templates and I am contrasting it to simple class template:

template <typename T> 
class Array { 
private: 
    T *ptr; 
    int size; 
public: 
    Array(T arr[], int s) : ptr(arr), size(s) {}
    void print() {
      for (int i = 0; i < size; i++) {
          std::cout << ptr[i] << " ";
      }
    }; 
}; 

where we don't need have angular brackets in the class declaration. I can't write, for example,

template <typename T> 
class Array<T> { 
private: 
    T *ptr; 
    int size; 
    ...

Only time I have seen angular brackets after class name is when we initialize template: Array<int> arr(a, 2);

Is class Tuple<T, Rest...> also template initialization?

Reference

[1] http://www.vishalchovatiya.com/variadic-template-cpp-implementing-unsophisticated-tuple/

Jarod42
  • 203,559
  • 14
  • 181
  • 302
Bruce
  • 33,927
  • 76
  • 174
  • 262
  • 2
    It's called a [partial template specialization](https://en.cppreference.com/w/cpp/language/partial_specialization). – cigien Mar 08 '21 at 02:46
  • 2
    You'd see it in a class template specialization: https://en.cppreference.com/w/cpp/language/template_specialization https://en.cppreference.com/w/cpp/language/partial_specialization – jtbandes Mar 08 '21 at 02:46
  • Thanks both! I am new to templates in general and baffled by the syntax at times. – Bruce Mar 08 '21 at 02:54

0 Answers0