vendredi 23 février 2018

C++ templates and alias

This will be used in a library and not like the example, the example below is made such that it just explains the question. I have a template class BaseType with a template specialization.

 template<...> 
 class BaseType; //Forward declare

 template<typename T>  
BaseType<T> {...implementation 1...};

 template<typename T, typename R>  
BaseType<T,R> {...implementation 2...};

I would now want to create an alias for the shared_ptr templates. Doing it for one of the template versions works fine.

template<typename T>
    using SlotType = std::shared_ptr<BaseType<T> >;

using EventArgSlot = SlotType<EventArgs>;

EventArgSlot slot1;

But how should I define the alias such that it also support this

using MessageIntegerSlot = SlotType<MessageArgs, int>;
MessageIntegerSlot slot2;

Just adding an additional alias with the same and an additional template parameter does not work

template<typename T, typename R>
       using SlotType = std::shared_ptr<BaseType<T,R> >;

Is this possible to solve in C++11/14?

Aucun commentaire:

Enregistrer un commentaire