mercredi 25 juillet 2018

Can I define templates for different sets of types?

I need to write a templated function, that behaves differently depending on the class of its parameter:

template<class ConatinerType>
bool myFunc(ConatinerType in){
//do some stuff
}

template<class NotAConatinerType>
bool myFunc(NotAConatinerType in){
//do something else
}

I am restricted to C++11, so static_if is off the table. Also, the classes of ConatinerType and NotAConatinerType are really large and might change in the future, so just adding a few exceptions by hand as a template specialization is not sensible either.

I am aware of the std::enable_if workaround, but how do I use it, if I need to apply it to two mutually distinct sets of classes?

Aucun commentaire:

Enregistrer un commentaire