命名空间
变体
操作

std::is_error_code_enum<std::io_errc>

来自 cppreference.cn
< cpp‎ | io‎ | io errc
定义于头文件 <ios>
template<>
struct is_error_code_enum<std::io_errc> : public std::true_type {};
(since 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 (const std::ios_base::failure& e)
    {
        std::cout << "Caught an ios_base::failure.\n";
        if (e.code() == std::io_errc::stream)
            std::cout << "The error code is std::io_errc::stream\n";
    }
}

输出

Caught an ios_base::failure.
The error code is std::io_errc::stream

[编辑] 参见

标识一个类为 error_code 枚举
(类模板) [编辑]
持有平台相关的错误码
(类) [编辑]
(C++11)
IO 流错误码
(枚举) [编辑]