vendredi 18 mai 2018

Template specialization duplicate parameters

Recently I have noticed the following problem with template specializations.

Note if we have the following specialization for f and the template parameter name is a very long type.

template <class T> void f(T t) {}

template <>
void f<VeryLongType>(VeryLongType t)
{
    using T = VeryLongType;
    // ...
}

Note this very long type name is duplicated 3 times. Also if f returns a value of this type, then another duplication will be introduced.

I am wondering if there exits some simplified syntax for this?

Maybe like the following:

template <>
void f<T = VeryLongType>(T t)
{
   // ...
}

Aucun commentaire:

Enregistrer un commentaire