Skip to content

Latest commit

 

History

History
87 lines (64 loc) · 1.78 KB

File metadata and controls

87 lines (64 loc) · 1.78 KB

operator<=>

  • 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

処理系

参照