CppDS.com

C++ 98 11 14 17 20 手册

std::is_error_code_enum<std::io_errc>

来自cppreference.com
< cpp‎ | io‎ | io errc
定义于头文件 <ios>
template< >
struct is_error_code_enum<std::io_errc> : public std::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 <iostream>
#include <fstream>
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 流的错误码
(枚举)
关闭