Detect operator support with decltype/SFINAE
A (somewhat) outdated article explores ways to use decltype along with SFINAE to detect if a type supports certain operators, such as == or < . Here's example code to detect if a class supports the < operator: template <class T> struct supports_less_than { static auto less_than_test(const T* t) -> decltype(*t < *t, char(0)) { } static std::array<char, 2> less_than_test(...) { } static const bool value = (sizeof(less_than_test((T*)0)) == 1); }; int main() { std::cout << std::boolalpha << supports_less_than<std::string>::value << endl; } This outputs true , since of course std::string supports