vendredi 8 mai 2015

How to make a template-dependent typedef more convenient?

I have several classes with all the same template arguments. They use OftenUsedType which is also a template. So I typedef it to R to have more convenient notation:

template <class T, int A, int B>
class Obj{
   typedef OftenUsedType<T, A, B> R;
}

Unfortunately, I have to do this in all classes which use OftenUsedType, since it depends on the template parameters.

The only way to make this a bit more convenient is to do the typedef in a class and inherit it to all classes which use it:

template <class T, int A, int B>
class ObjTypedef{
   typedef OftenUsedType<T, A, B> R;
}

template <class T, int A, int B>
class Obj : public ObjTypedef<T, A, B>{
}

But I still have to inherit the typedef class into all classes which use the type...

Is there a more convenient, good-style way to do it?

Aucun commentaire:

Enregistrer un commentaire