std::is_class
提供: cppreference.com
<tbody>
</tbody>
| ヘッダ <type_traits> で定義
|
||
template< class T > struct is_class; |
(C++11以上) | |
T が非共用体クラス型かどうか調べます。 T がクラス型 (共用体は除く) であれば、 true に等しいメンバ定数 value が提供されます。 そうでなければ、 value は false に等しくなります。
is_class または is_class_v (C++17以上) に対して特殊化を追加するプログラムは未定義です。
テンプレート引数
| T | - | 調べる型 |
ヘルパー変数テンプレート
<tbody> </tbody> template< class T > inline constexpr bool is_class_v = is_class<T>::value; |
(C++17以上) | |
std::integral_constant から継承
メンバ定数
value [静的] |
T が非共用体クラス型ならば true、そうでなければ false (パブリック静的メンバ定数) |
メンバ関数
operator bool |
オブジェクトを bool に変換します。 value を返します (パブリックメンバ関数) |
operator() (C++14) |
value を返します (パブリックメンバ関数) |
メンバ型
| 型 | 定義 |
value_type
|
bool
|
type
|
std::integral_constant<bool, value>
|
実装例
namespace detail {
template <typename T, typename = typename std::enable_if<!std::is_union<T>::value>::type>
std::true_type test(int T::*);
template <typename T>
std::false_type test(...);
}
template <class T>
struct is_class : decltype(detail::test<T>(nullptr))
{};
|
例
Run this code
#include <iostream>
#include <type_traits>
struct A {};
class B {};
enum class C {};
int main()
{
std::cout << std::boolalpha;
std::cout << std::is_class<A>::value << '\n';
std::cout << std::is_class<B>::value << '\n';
std::cout << std::is_class<C>::value << '\n';
std::cout << std::is_class<int>::value << '\n';
}
出力:
true
true
false
false
関連項目
(C++11) |
型が共用体型かどうか調べます (クラステンプレート) |