How do I use the following struct:
struct point
{
int x;
int y;
int z;
};
as a key for std::map<point, bool>? How should I define operator< for two points?
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.
Standard library containers like
std::maprequire that your ordering is a “Strict Weak Ordering”, so you have to be very careful when designing one.The typical approach for a 3-ary tuple looks like this:
It’s like a comparator for just
x, but with the difference that if the twoxs are the same, you fall through to compareys. If they are the same, then similarly you fall through to thezcomparison.