namespace std {
template <class T>
struct is_error_condition_enum : public false_type {};
template <>
struct is_error_condition_enum<errc> : true_type {};
template <class T>
inline constexpr bool is_error_condition_enum_v
= is_error_condition_enum<T>::value; // C++17
}
概要
error_condition
のエラー値として見なせる列挙型かどうかを判定する。
is_error_condition_enum
はデフォルトではfalse_type
を継承し、is_error_condition_enum<T>::value
はfalse
となる。
is_error_condition_enum<T>::value == true
であることを要求する関数(error_condition
のコンストラクタ、および、代入演算子)にユーザー定義の列挙型を渡したい場合は、is_error_condition_enum
クラスを特殊化し、true_type
を継承するよう特殊化する必要がある。
標準では、errc
列挙型に対するtrue_type
の特殊化を提供する。
例
#include <system_error>
enum class user_defined_error {
success = 0,
error = 1,
};
int main()
{
static_assert(std::is_error_condition_enum<std::errc>::value, "");
static_assert(!std::is_error_condition_enum<user_defined_error>::value, "");
}
出力
バージョン
言語
- 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: 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++:
関連項目
error_condition
error_condition::error_condition
error_condition::operator=
errc
error_code
is_error_code_enum