R
Ralf Goertz
Hi,
ist it possible to have a map for which there are distinct keys k1 and
key with k1!=k2 and both k1<k2 and k2<k1 returning false? I'd like to
have something like
struct foo {
int k[10];
bool operator<(const foo& rhs) const {
for (int i=0;i<9;++i)
if (k!=rhs.k) return k<rhs.k;
return false;
}
};
std::map<foo,int> evaluation_map;
The reason is that although two variables of type foo might be different
in k[9] there evaluation only depends on k[0]…k[8]. If I understand it
correctly, a map never uses operator==, therefore the above shouldn't
produce undefined behaviour, right?
ist it possible to have a map for which there are distinct keys k1 and
key with k1!=k2 and both k1<k2 and k2<k1 returning false? I'd like to
have something like
struct foo {
int k[10];
bool operator<(const foo& rhs) const {
for (int i=0;i<9;++i)
if (k!=rhs.k) return k<rhs.k;
return false;
}
};
std::map<foo,int> evaluation_map;
The reason is that although two variables of type foo might be different
in k[9] there evaluation only depends on k[0]…k[8]. If I understand it
correctly, a map never uses operator==, therefore the above shouldn't
produce undefined behaviour, right?