- map[meta header]
- std[meta namespace]
- function template[meta id-type]
- cpp20[meta cpp]
namespace std {
template <class Key, class T, class Compare, class Allocator>
synth-three-way-result<pair<const Key, T>>
operator<=>(const map<Key,T,Compare,Allocator>& x,
const map<Key,T,Compare,Allocator>& y); // (1) C++20
}- pair[link /reference/utility/pair.md]
mapオブジェクトの三方比較を行う。
- 型 (
const)pair<const Key, T>の値に対してoperator<=>が定義されるか、型 (const)pair<const Key, T>の値に対してoperator<が定義され全順序をもつこと
return lexicographical_compare_three_way(
x.begin(), x.end(),
y.begin(), y.end(),
synth-three-way);- lexicographical_compare_three_way[link /reference/algorithm/lexicographical_compare_three_way.md]
- begin()[link begin.md]
- end()[link end.md]
線形時間
- この演算子により、以下の演算子が使用可能になる (C++20):
operator<operator<=operator>operator>=
#include <cassert>
#include <map>
int main()
{
std::map<int,char> m1;
m1[0] = 'a';
auto m2 = m1;
assert((m1 <=> m2) == 0);
m2[0] = 'b';
assert((m1 <=> m2) != 0);
return 0;
}- C++20
- Clang:
- GCC: 10
- Visual C++: ??
- P1614R2 The Mothership has Landed
- C++20での三方比較演算子の追加と、関連する演算子の自動導出