lundi 5 janvier 2015

limit universal reference to a single type using aliasing

I have a member function of a class in which I'd like to use perfect forwarding for one of the parameters. However, the function being forwarded to only accepts a single argument of type c2Type, so I'd like the calling function also to only accept c2Type arguments, but obviously have to keep the universal reference to do the forwarding. It seems it can be accomplished using a default template parameter like so:



class c2Type
{
// some data members...
};

template<typename T, typename isC2Type = typename std::enable_if<
std::is_same<c2Type, typename std::decay<T>::type>::value>::type>
void configurationMessageHandler(T&& message)
{
// some stuff...
mapAddress(std::forward<c2Type>(message));
}

mapAddress(c2Type&& message)
{
// do stuff...
};


However, I need to check for this type on several member functions, and also such a long template seems unfriendly and unreadable. What I'd like to is create an alias for isC2Type like



template<typename T>
using isC2Type = typename std::enable_if<
std::is_same<c2Type, typename std::decay<T>::type>::value>::type;


which I thought would make the configurationMessageHandler template look like



template<typename T, isC2Type<T>>


but that doesn't compile. How can I properly use aliases in this case?


Aucun commentaire:

Enregistrer un commentaire