最終更新日時(UTC):
が更新

履歴 編集

function template
<deque>

std::operator<=>(C++20)

namespace std {
  template <class T, class Allocator>
  synth-three-way-result<T>
    operator<=>(const deque<T, Allocator>& x,
                const deque<T, Allocator>& y); // (1) C++20
}

概要

dequeオブジェクトの三方比較を行う。

テンプレートパラメータ制約

  • 型 (const) T の値に対してoperator<=>が定義されるか、型 (const) T の値に対してoperator<が定義され全順序をもつこと

効果

計算量

線形時間

備考

  • この演算子により、以下の演算子が使用可能になる (C++20):
    • operator<
    • operator<=
    • operator>
    • operator>=

#include <cassert>
#include <deque>

int main ()
{
  std::deque<int> c1 = {1, 2, 3};
  std::deque<int> c2 = {1, 2, 3};
  std::deque<int> c3 = {1, 2, 3, 4};

  // 要素数と要素の値が等しい
  assert((c1 <=> c2) == 0);

  // 要素の値は(左辺の要素数分まで)等しいが要素数が異なる
  assert((c1 <=> c3) != 0);
}

出力

バージョン

言語

  • C++20

処理系

参照