- 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
- Clang:
- GCC: 10 [mark verified]
- Visual C++: ??
- P1614R2 The Mothership has Landed
- C++20での三方比較演算子の追加と、関連する演算子の自動導出