- system_error[meta header]
- std[meta namespace]
- class template[meta id-type]
- cpp11[meta cpp]
namespace std {
template <class T>
struct is_error_code_enum : public false_type {};
template <class T>
inline constexpr bool is_error_code_enum_v = is_error_code_enum<T>::value; // C++17
}
- false_type[link /reference/type_traits/false_type.md]
error_code
のエラー値として見なせる列挙型かどうかを判定する。
is_error_code_enum
はデフォルトではfalse_type
を継承し、is_error_code_enum<T>::value
はfalse
となる。
is_error_code_enum<T>::value == true
であることを要求する関数(error_code
のコンストラクタ、および、代入演算子)にユーザー定義の列挙型を渡したい場合は、is_error_code_enum
クラスを特殊化し、true_type
を継承するよう特殊化する必要がある。
標準では、io_errc
列挙型とfuture_errc
列挙型に対するtrue_type
の特殊化を提供する。
#include <system_error>
#include <ios>
#include <future>
enum class user_defined_error {
success = 0,
error = 1,
};
int main()
{
static_assert(std::is_error_code_enum<std::io_errc>::value, "");
static_assert(std::is_error_code_enum<std::future_errc>::value, "");
static_assert(!std::is_error_code_enum<user_defined_error>::value, "");
}
- std::is_error_code_enum[color ff0000]
- std::io_errc[link ../ios/io_errc.md]
- std::future_errc[link ../future/future_errc.md]
- std::future_errc[link ../future/future_errc.md]
- C++11
- Clang: 3.0, 3.1, 3.2, 3.3, 3.4, 3.5.0, 3.6.0, 3.7.0, 3.8.0
- GCC:
- GCC, C++11 mode: 4.4.7, 4.5.4, 4.6.4, 4.7.0, 4.7.3, 4.8.2, 4.9.0, 4.9.1, 4.9.2, 5.1.0, 5.2.0, 6.0.0
- ICC: ??
- Visual C++:
GCC では、4.4 から is_error_code_enum
が提供されているものの、future_errc
は 4.5 から、io_errc
は 5.1 からのサポートである。