dimanche 26 avril 2015

Handling zero-argument variadic template in C++11

Consider the following artificial example:

template <typename T, typename... Args>
struct A {
  typedef T Type;
};

Using A with 1 or more arguments works while using it with zero arguments fails as expected:

error: wrong number of template arguments (0, should be 1 or more)

Is it possible to make A handle the case of zero template arguments defining A::Type to int if there are no arguments and to the first template argument if there are?

Aucun commentaire:

Enregistrer un commentaire