set, map , lower_bound sort, , ( , a <).
3 :
- :
not (a < a) - :
a < b not (b < a) - transitive:
a < b b < c a < c
<.
, , ( not (a < b) and not (b < a) ). set map , multiset multimap .
, , , ==, . - <.
, - , < ( == ), . , std::tuple<std::string, std::string> , ; , std::tuple<std::string const&, std::string const&> , std::tie.
, :
struct comparator {
bool operator()(Pair const& left, Pair const& right) const {
return std::tie( left.a, left.b)
< std::tie(right.a, right.b);
}
};
. , , . , , , , (, )
EDIT: , .
, , , a b . , ; , :
struct comparator {
bool operator()(Pair const& left, Pair const& right) const {
auto uleft = left.a < left.b ? std::tie(left.a, left.b)
: std::tie(left.b, left.a);
auto uright = right.a < right.b ? std::tie(right.a, right.b)
: std::tie(right.b, right.a);
assert(get<0>(uleft) <= get<1>(uleft) and "Incorrect uleft");
assert(get<0>(uright) <= get<1>(uright) and "Incorrect uright");
return uleft < uright;
}
};