Is the "==" operator required to be defined to use std::find
Posted
by user144182
on Stack Overflow
See other posts from Stack Overflow
or by user144182
Published on 2010-05-08T14:15:27Z
Indexed on
2010/05/08
14:28 UTC
Read the original article
Hit count: 183
Let's say I have:
class myClass
std::list<myClass> myList
where myClass does not define the == operator and only consists of public fields.
In both VS2010 and VS2005 the following does not compile:
myClass myClassVal = myList.front();
std::find( myList.begin(), myList.end(), myClassVal )
complaining about lack of == operator.
I naively assumed it would do a value comparison of the myClass object's public members, but I am almost positive this is not correct.
I assume if I define a == operator or perhaps use a functor instead, it will solve the problem.
Alternatively, if my list was holding pointers instead of values, the comparison would work.
Is this right or should I be doing something else?
© Stack Overflow or respective owner