namespace std {
bool operator==(const error_code& lhs, const error_code& rhs) noexcept; // (1) C++11
bool operator==(const error_code& lhs, const error_condition& rhs) noexcept; // (2) C++11
bool operator==(const error_condition& lhs, const error_condition& rhs) noexcept; // (3) C++11
// (2)により以下のオーバーロードが使用可能になる (C++20)
bool operator==(const error_condition& lhs, const error_code& rhs) noexcept; // (4) C++11
}
概要
error_code
, error_condition
の等値比較を行う
戻り値
-
(1) :
lhs.category() == rhs.category() && lhs.value() == rhs.value()
-
(2) :
lhs.category().equivalent(lhs.value(), rhs) || rhs.category().equivalent(lhs, rhs.value())
-
(3) :
lhs.category() == rhs.category() && lhs.value() == rhs.value()
-
(4) :
rhs.category().equivalent(rhs.value(), lhs) || lhs.category().equivalent(rhs, lhs.value())
例外
投げない
例
#include <iostream>
#include <system_error>
int main()
{
std::error_code ec1 = std::make_error_code(std::errc::invalid_argument);
std::error_code ec2 = std::make_error_code(std::errc::permission_denied);
std::error_condition ed1 = std::make_error_condition(std::errc::invalid_argument);
std::error_condition ed2 = std::make_error_condition(std::errc::permission_denied);
std::cout << std::boolalpha;
std::cout << "error_code == error_code : " << (ec1 == ec1) << std::endl;
std::cout << "error_code == error_code : " << (ec1 == ec2) << std::endl;
std::cout << "error_code == error_condition : " << (ec1 == ed1) << std::endl;
std::cout << "error_code == error_condition : " << (ec1 == ed2) << std::endl;
std::cout << "error_condition == error_condition : " << (ed1 == ed1) << std::endl;
std::cout << "error_condition == error_condition : " << (ed1 == ed2) << std::endl;
}
23
#include <iostream>
#include <system_error>
int main()
{
std::error_code ec1 = std::make_error_code(std::errc::invalid_argument);
std::error_code ec2 = std::make_error_code(std::errc::permission_denied);
std::error_condition ed1 = std::make_error_condition(std::errc::invalid_argument);
std::error_condition ed2 = std::make_error_condition(std::errc::permission_denied);
std::cout << std::boolalpha;
std::cout << "error_code == error_code : " << (ec1 == ec1) << std::endl;
std::cout << "error_code == error_code : " << (ec1 == ec2) << std::endl;
std::cout << "error_code == error_condition : " << (ec1 == ed1) << std::endl;
std::cout << "error_code == error_condition : " << (ec1 == ed2) << std::endl;
出力
error_code == error_code : true
error_code == error_code : false
error_code == error_condition : true
error_code == error_condition : false
error_condition == error_condition : true
error_condition == error_condition : false
バージョン
言語
- C++11
処理系
- Clang: ??
- GCC: 4.7.0 ✅
- ICC: ??
- Visual C++: 2010 ✅
参照
- P1614R2 The Mothership has Landed
- C++20での三方比較演算子の追加と、関連する演算子の自動導出