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

履歴 編集

function template
<array>

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

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

概要

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

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

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

効果

計算量

線形時間

備考

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

#include <iostream>
#include <array>

int main()
{
  std::array<int, 3> x = {1, 2, 3};
  std::array<int, 3> y = {1, 2, 3};

  if ((x <=> y) == 0) {
    std::cout << "equal" << std::endl;
  }
  else {
    std::cout << "not equal" << std::endl;
  }
}

出力

equal

バージョン

言語

  • C++20

処理系

参照