std::is_error_code_enum<std::io_errc>
來自 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 [靜態] |
true (public static 成員常量) |
成員函式
operator bool |
將物件轉換為 bool,返回 value (公開成員函式) |
operator() (C++14) |
返回 value (公開成員函式) |
成員型別
型別 | 定義 |
value_type
|
bool |
型別
|
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) |
I/O 流錯誤碼 (列舉) |