3

I found a strange code about template in SO. It is like declaring template signature twice.

template <typename Tf, Tf F>
class Collection;

template <typename K, typename ... I, HashFunction<K, I...> F>   //<-- #B1
class Collection<HashFunction<K, I...>, F>    //<-- <> again!          #B2
 {    /*.......*/ }

What is the meaning of repeating declaration of the template (#B1 & #B2)?
Which C++ specification allows <> twice?
What is it called? ... I want to dig more about it.
Is it a kind of alias?
How can it be useful, generally?

I don't find such signature in cppreference.
Is it a bleeding-edge C++ syntax?

Community
  • 1
  • 1
javaLover
  • 6,347
  • 2
  • 22
  • 67

1 Answers1

7
// A
template <typename Tf, Tf F>
class Collection;


// B
template <typename K, typename ... I, HashFunction<K, I...> F>
class Collection<HashFunction<K, I...>, F> 
 {    /*.......*/ }

//A is the primary class-template Collection, while //B is a partial-specialization of the class-template Collection. Basically, you are specializing :

template <typename Tf, Tf F>
class Collection;

on the class-template:

template<typename K, typename ... I>
class HashFunction<K, I...>;

So, if any instantiated type of HashFunction is used as template Argument to Collection, the partial specialization //B gets selected for instantiation.


WhiZTiM
  • 21,207
  • 4
  • 43
  • 68