I use my own class as a key type for std::map. How the map implementation determines when two objects are equal?
I know that I can determine operator< or Comp type to arrange elements. But I can find nothing about equality.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It’s possible to make the comparison using just
operator<, so it doesn’t require you to defineoperator==as well. Basically, if one is not less than the other, and the other is not less than the first, they must be equal. This is a possible utility function implementation of such: