std::error_condition
来自 cppreference.cn
定义于头文件 <system_error> |
||
class error_condition; |
(since C++11) | |
std::error_condition
保留了一个平台无关的值,用于标识错误条件。 类似于 std::error_code,它由一个整数值和一个 std::error_category 唯一标识,但与 std::error_code 不同,该值不依赖于平台。
一个典型的实现包含一个整数数据成员(值)和一个指向 std::error_category 的指针。
目录 |
[edit] 成员函数
构造一个 error_condition (公共成员函数) | |
替换内容 (公共成员函数) | |
替换内容 (公共成员函数) | |
将 error_condition 设置为 generic_category 中的值 0(公共成员函数) | |
获取 error_condition 的值(公共成员函数) | |
获取此 error_condition 的 error_category (公共成员函数) | |
获取解释性字符串 (公共成员函数) | |
检查值是否为非零 (公共成员函数) |
[edit] 非成员函数
(在 C++20 中移除)(在 C++20 中移除)(C++20) |
比较 error_condition 和 error_code (函数) |
[edit] 辅助类
(C++11) |
将枚举标识为 std::error_condition (类模板) |
对 std::error_condition 的哈希支持 (类模板特化) |
[edit] 注解
比较 std::error_code 和 std::error_condition
是由它们的错误类别定义的。 值得注意的是,std::generic_category 的错误条件可能与特定类别(例如 std::system_category)的错误代码相等,如果它们代表同一种错误。
一个 std::errc 值可以通过隐式转换为 std::error_condition
来与错误代码进行比较。
运行此代码
#include <cerrno> #include <iostream> #include <system_error> #include <Windows.h> int main() { std::error_code ec{ERROR_FILE_EXISTS, std::system_category()}; std::error_condition econd{EEXIST, std::generic_category()}; std::cout.setf(std::ios::boolalpha); std::cout << (ec == econd) << '\n'; // typically true std::cout << (ec == std::errc::file_exists) << '\n'; // ditto std::cout << (ec == make_error_code(std::errc::file_exists)) << '\n'; // false: // different category }
可能的输出
true true false
[edit] 参见
(C++11) |
保留平台相关的错误代码 (类) |
(C++11) |
错误类别的基类 (类) |
为一个 errc 值 e 创建一个错误条件(函数) |