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

履歴 編集

function
<system_error>

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

namespace std {
  strong_ordering
    operator<=>(const error_condition& lhs,
                const error_condition& rhs) noexcept; // (1) C++20
}

概要

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

効果

以下と等価:

if (auto c = lhs.category() <=> rhs.category(); c != 0)
  return c;
return lhs.value() <=> rhs.value();

例外

投げない

備考

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

#include <cassert>
#include <system_error>

int main()
{
  std::error_condition ec1 = std::make_error_condition(std::errc::invalid_argument);
  std::error_condition ec2 = std::make_error_condition(std::errc::invalid_argument);
  std::error_condition ec3 = std::make_error_condition(std::errc::permission_denied);

  assert((ec1 <=> ec2) == 0);
  assert((ec1 <=> ec3) != 0);
}

出力

バージョン

言語

  • C++20

処理系

参照