Namespaces
Variants

std:: is_object

From cppreference.net
Metaprogramming library
Type traits
Type categories
(C++11)
(C++11) ( DR* )
is_object
(C++11)
(C++11)
Type properties
(C++11)
(C++11)
(C++14)
(C++11) (deprecated in C++26)
(C++11) ( until C++20* )
(C++11) (deprecated in C++20)
(C++11)
Type trait constants
Metafunctions
(C++17)
Supported operations
Relationships and property queries
Type modifications
Type transformations
(C++11) (deprecated in C++23)
(C++11) (deprecated in C++23)
(C++11)
(C++11) ( until C++20* ) (C++17)

Compile-time rational arithmetic
Compile-time integer sequences
定義先ヘッダ <type_traits>
template < class T >
struct is_object ;
(C++11以降)

std::is_object UnaryTypeTrait です。

T オブジェクト型 (つまり、関数型、参照型、または void 型以外の、CV修飾可能性のある任意の型)である場合、メンバー定数 value true に等しい値を提供します。それ以外の型の場合、 value false です。

プログラムが std::is_object または std::is_object_v に対する特殊化を追加する場合、動作は未定義です。

目次

テンプレートパラメータ

T - チェックする型

ヘルパー変数テンプレート

template < class T >
constexpr bool is_object_v = is_object < T > :: value ;
(C++17以降)

std::integral_constant から継承 std:: integral_constant

メンバ定数

value
[static]
true T がオブジェクト型の場合、 false それ以外の場合
(public static member constant)

メンバ関数

operator bool
オブジェクトを bool に変換、 value を返す
(public member function)
operator()
(C++14)
value を返す
(public member function)

メンバ型

定義
value_type bool
type std:: integral_constant < bool , value >

実装例

template<class T>
struct is_object : std::integral_constant<bool,
                       std::is_scalar<T>::value ||
                       std::is_array<T>::value ||
                       std::is_union<T>::value ||
                       std::is_class<T>::value> {};

#include <iomanip>
#include <iostream>
#include <type_traits>
#define IS_OBJECT(...) \
    std::cout << std::boolalpha << std::left << std::setw(9) << #__VA_ARGS__ \
              << (std::is_object_v<__VA_ARGS__> ? " is object\n" \
                                                : " is not an object\n")
int main()
{
    class cls {};
    IS_OBJECT(void);
    IS_OBJECT(int);
    IS_OBJECT(int&);
    IS_OBJECT(int*);
    IS_OBJECT(int*&);
    IS_OBJECT(cls);
    IS_OBJECT(cls&);
    IS_OBJECT(cls*);
    IS_OBJECT(int());
    IS_OBJECT(int(*)());
    IS_OBJECT(int(&)());
}

出力:

void      is not an object
int       is object
int&      is not an object
int*      is object
int*&     is not an object
cls       is object
cls&      is not an object
cls*      is object
int()     is not an object
int(*)()  is object
int(&)()  is not an object

関連項目

(C++11)
型がスカラ型かどうかをチェックする
(クラステンプレート)
(C++11)
型が配列型かどうかをチェックする
(クラステンプレート)
(C++11)
型が共用体型かどうかをチェックする
(クラステンプレート)
(C++11)
型が非共用体クラス型かどうかをチェックする
(クラステンプレート)