- utility[meta header]
- std[meta namespace]
- pair[meta class]
- function template[meta id-type]
friend constexpr common_comparison_category_t<synth-three-way-result<T1>, synth-three-way-result<T2>>
operator<=>(const pair& x, const pair& y);
- common_comparison_category_t[link /reference/compare/common_comparison_category.md]
2つのpair
の三方比較を行う。
以下と等価:
if (auto c = synth-three-way(x.first, y.first); c != 0)
return c;
return synth-three-way(x.second, y.second);
- この演算子により、以下の演算子が使用可能になる (C++20):
operator<
operator<=
operator>
operator>=
#include <cassert>
#include <utility>
#include <string>
int main()
{
std::pair<int, std::string> p1(1, "aaa");
std::pair<int, std::string> p2(1, "aaa");
std::pair<int, std::string> p3(2, "bbb");
assert((p1 <=> p2) == 0);
assert((p1 <=> p3) != 0);
assert(p1 < p3);
assert(p1 <= p3);
assert(p3 > p1);
assert(p3 >= p1);
}
- P1614R2 The Mothership has Landed
- C++20での三方比較演算子の追加と、関連する演算子の自動導出