Namespaces
Variants
Views
Actions

std::is_error_code_enum<std::io_errc>

From cppreference.com
< cpp‎ | io‎ | io errc
Revision as of 17:15, 2 November 2012 by P12bot (Talk | contribs)

Template:ddcl list begin <tr class="t-dsc-header">

<td>
Defined in header <ios>
</td>

<td></td> <td></td> <tr class="t-dcl ">

<td >
template< >
struct is_error_code_enum<std::io_errc> : public std::true_type { };
</td>

<td class="t-dcl-nopad"> </td> <td > (since C++11) </td> </tr> Template:ddcl list end

This specialization of std::is_error_code_enum informs other library components that values of type std::io_errc are enumerations that hold error codes, which makes them implicitly convertible and assignable to objects of type std::error_code.

Contents

Inherited from std::integral_constant

Member constants

value
[static]
true
(public static member constant)

Member functions

operator bool
converts the object to bool, returns value
(public member function)

Member types

Type Definition
value_type bool
type std::integral_constant<bool, value>

Example

The comparison between e.code() and std::io_errc::stream compiles because 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";
    }
}

Output:

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

See also

Template:cpp/error/error code/dcl list is error code enumTemplate:cpp/error/dcl list error codeTemplate:cpp/io/dcl list io errc