std::is_error_code_enum<std::io_errc>
来自cppreference.com
在标头 <ios> 定义 | ||
template<> struct is_error_code_enum<std::io_errc>:publicstd::true_type{}; | (C++11 起) | |
此 std::is_error_code_enum 特化指示其他库组件 std::io_errc 的值是保有错误码的枚举,这使得它们可以隐式转换到并赋值给 std::error_code 类型的对象。
目录 |
继承自 std::integral_constant
成员常量
value [静态] | true (公开静态成员常量) |
成员函数
operator bool | 将对象转换到 bool,返回 value (公开成员函数) |
operator() (C++14) | 返回 value (公开成员函数) |
成员类型
类型 | 定义 |
value_type | bool |
type | std::integral_constant<bool, value> |
[编辑]示例
e.code() 与 std::io_errc::stream 之间的比较能编译,因为 std::is_error_code_enum<std::io_errc>::value==true。
运行此代码
#include <fstream>#include <iostream> int main(){std::ifstream f("doesn't exist");try{ f.exceptions(f.failbit);}catch(conststd::ios_base::failure& e){std::cout<<"捕获了 ios_base::failure。\n";if(e.code()==std::io_errc::stream)std::cout<<"错误码为 std::io_errc::stream\n";}}
输出:
捕获了 ios_base::failure。 错误码为 std::io_errc::stream
[编辑]参阅
(C++11) | 鉴别类是否可作为 error_code 枚举 (类模板) |
(C++11) | 保有依赖于平台的错误码 (类) |
(C++11) | 输入/输出流的错误码 (枚举) |