Skip to content

Latest commit

 

History

History
78 lines (60 loc) · 1.74 KB

op_compare_3way.md

File metadata and controls

78 lines (60 loc) · 1.74 KB

operator<=>

  • system_error[meta header]
  • std[meta namespace]
  • function[meta id-type]
  • cpp20[meta cpp]
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();
  • category()[link category.md]
  • value()[link value.md]

例外

投げない

備考

  • この演算子により、以下の演算子が使用可能になる (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);
}
  • std::make_error_condition[link /reference/system_error/make_error_condition.md]
  • std::errc::invalid_argument[link /reference/system_error/errc.md]
  • std::errc::permission_denied[link /reference/system_error/errc.md]

出力

バージョン

言語

  • C++20

処理系

参照