std::is_scoped_enum
From cppreference.com
| ヘッダ <type_traits> で定義 |
||
| template< class T > struct is_scoped_enum; |
(C++23から) | |
std::is_scoped_enumは単項型特性 (UnaryTypeTrait)である。
Tがスコープ付き列挙型であるかをチェックする。Tがスコープ付き列挙型である場合、trueに等しいメンバ定数valueを提供する。そうでない場合、valueはfalseに等しい。
プログラムがstd::is_scoped_enumまたはstd::is_scoped_enum_vの特殊化を追加した場合、その動作は未定義である。
目次 |
[編集] テンプレートパラメータ
| T | - | チェックする型 |
[編集] ヘルパー変数テンプレート
| template< class T > constexpr bool is_scoped_enum_v = is_scoped_enum<T>::value; |
(C++23から) | |
std::integral_constant から継承
メンバ定数
| value [static] |
Tがスコープ付き列挙型である場合はtrue、そうでない場合はfalse(公開静的メンバ定数) |
メンバ関数
| operator bool |
オブジェクトを bool に変換し、value を返します。 (public member function) |
| operator() (C++14) |
value を返します。 (public member function) |
メンバ型
| 型 | 定義 |
value_type
|
bool |
type
|
std::integral_constant<bool, value> |
[編集] 備考
| 機能テストマクロ | 値 | 規格 | 機能 |
|---|---|---|---|
__cpp_lib_is_scoped_enum |
202011L |
(C++23) | std::is_scoped_enum
|
[編集] 考えられる実装
namespace detail { void test_conversion(...); // selected when E is complete and scoped void test_conversion(int) = delete; // selected when E is complete and unscoped template<class E> concept is_scoped_enum_impl = std::is_enum_v<E> && // checked first requires { detail::test_conversion(E{}); }; // ill-formed before overload resolution // when E is incomplete } // namespace detail template<class T> struct is_scoped_enum : std::bool_constant<detail::is_scoped_enum_impl<T>> {}; |
[編集] 例
このコードを実行
#include <type_traits> static_assert(std::is_scoped_enum_v<int> == false); class A {}; static_assert(std::is_scoped_enum_v<A> == false); enum B { self_test = std::is_scoped_enum_v<B> }; static_assert(std::is_scoped_enum_v<B> == false); static_assert(!self_test); enum struct C { final, import, module }; static_assert(std::is_scoped_enum_v<C> == true); enum class D : int { pre, post, override }; static_assert(std::is_scoped_enum_v<D> == true); enum class E; static_assert(std::is_scoped_enum_v<E> == true); int main() {}
[編集] 関連項目
| (C++11) |
型が整数型であるかをチェックする (クラステンプレート) |
| (C++11) |
型が算術型であるかをチェックする (クラステンプレート) |
| (C++11) |
型がスカラ型であるかをチェックする (クラステンプレート) |
| (C++11) |
型が列挙型であるかをチェックする (クラステンプレート) |