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

履歴 編集

function template
<inplace_vector>

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

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

概要

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

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

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

効果

計算量

線形時間

備考

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

#include <cassert>
#include <print>
#include <inplace_vector>

int main()
{
  std::inplace_vector<int, 5> iv1 = {1, 2, 3};
  std::inplace_vector<int, 5> iv2 = {1, 2, 3};
  std::inplace_vector<int, 5> iv3 = {1, 2, 4};

  // 三方比較
  assert((iv1 <=> iv2) == 0);
  assert((iv1 <=> iv3) < 0);

  // operator<=>から自動導出される比較演算子
  std::println("{}", iv1 < iv3);  // true:  {1,2,3} < {1,2,4}
  std::println("{}", iv1 <= iv2); // true:  {1,2,3} <= {1,2,3}
  std::println("{}", iv3 > iv1);  // true:  {1,2,4} > {1,2,3}
  std::println("{}", iv1 >= iv2); // true:  {1,2,3} >= {1,2,3}
}

出力

true
true
true
true

バージョン

言語

  • C++26

処理系

参照