std::is_error_code_enum<std::io_errc>
From cppreference.com
| ヘッダ <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 [static] |
true (公開静的メンバ定数) |
メンバ関数
| operator bool |
オブジェクトを bool に変換し、value を返します。 (public member function) |
| operator() (C++14) |
value を返します。 (public member function) |
メンバ型
| 型 | 定義 |
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
[編集] 関連項目
| (C++11) |
クラスをerror_code列挙型として識別する(クラステンプレート) |
| (C++11) |
プラットフォーム依存のエラーコードを保持する (クラス) |
| (C++11) |
IOストリームのエラーコード (enum) |