dimanche 21 juillet 2019

How to check if specific overload of an operator exists at compile time in C++?

I have a class which overloads the () operator for multiple input types i.e.

struct Type {
    void operator()(int);
    void operator()(std::string);
};

Now, I would like to use SFINAE to check if a specific overload of () operator exists or not i.e.

if (Type()(std::string) overload exists) {
    // do something...
}

Is this possible to do in C++11? (I cannot use C++14 or C++17).

Note: In the actual code, there is a template class which accepts a class type with certain properties. There is a member function in this template which will be specialized based on whether certain specific overloads of () operator for the parameter type exists or not.

Aucun commentaire:

Enregistrer un commentaire