virtual bool equivalent(int code, const error_condition& condition) const noexcept; // (1)
virtual bool equivalent(const error_code& code, int condition) const noexcept; // (2)
概要
エラーコードとエラー状態の等値比較を行う。
戻り値
- (1) :
return default_error_condition(code) == condition;
- (2) :
return *this == code.category() && code.value() == condition;
例外
投げない
例
#include <iostream>
#include <system_error>
#include <string>
#include <cerrno>
int main()
{
const std::error_category& cat = std::generic_category();
std::error_code generic_ec(ENOTDIR, std::generic_category());
std::error_code system_ec(ENOTDIR, std::system_category());
std::cout << std::boolalpha;
std::cout << cat.equivalent(ENOTDIR, generic_ec.default_error_condition()) << std::endl;
std::cout << cat.equivalent(ENOTDIR, system_ec.default_error_condition()) << std::endl;
std::cout << cat.equivalent(generic_ec, ENOTDIR) << std::endl;
std::cout << cat.equivalent(system_ec, ENOTDIR) << std::endl;
}
xxxxxxxxxx
#include <iostream>
#include <system_error>
#include <string>
#include <cerrno>
int main()
{
const std::error_category& cat = std::generic_category();
std::error_code generic_ec(ENOTDIR, std::generic_category());
std::error_code system_ec(ENOTDIR, std::system_category());
std::cout << std::boolalpha;
std::cout << cat.equivalent(ENOTDIR, generic_ec.default_error_condition()) << std::endl;
std::cout << cat.equivalent(ENOTDIR, system_ec.default_error_condition()) << std::endl;
std::cout << cat.equivalent(generic_ec, ENOTDIR) << std::endl;
std::cout << cat.equivalent(system_ec, ENOTDIR) << std::endl;
}
出力
true
false
true
false
バージョン
言語
- C++11
処理系
- Clang: ??
- GCC: 4.6.1 ✅
- ICC: ??
- Visual C++: 2010 ✅