0

How do you check if a container in C++ supports the equality operator?

So basically, I want to implement a generic equality checking function which looks like this

template <class C>
bool operator==(const C& c1, const C& c2) {
    return c1 == c2;
}

And I want to allow this function to work only on classes which have the equality operator defined. Is there any way to check for the presence of the equality operator in a class?

  • this function *is* already working only for `C`s that have an `operator==`. What do you want to happen when `C` has no `operator==` ? Do something else? Produce a nicer error message? – 463035818_is_not_a_number May 23 '22 at 17:59

0 Answers0