最終更新日時(UTC):
が更新

履歴 編集

class template
<type_traits>

std::is_compound(C++11)

namespace std {
  template <class T>
  struct is_compound;

  template <class T>
  inline constexpr bool is_compound_v = is_compound<T>::value; // C++17
}

概要

Tが複合型 (Compound types) か調べる。複合型は、配列型、関数型、ポインタ型、参照型、クラス型、共用型、列挙型、メンバポインタ型、およびそれらのcv修飾を含む。

効果

is_compoundは、型Tが複合型であるならばtrue_typeから派生し、そうでなければfalse_typeから派生する。

備考

複合型は、すべての型の集合から、単純型の集合を除いたものに等しい。

#include <type_traits>

static_assert(std::is_compound<int*>::value == true, "value == true, int* is compound");
static_assert(std::is_same<std::is_compound<int*>::value_type, bool>::value, "value_type == bool");
static_assert(std::is_same<std::is_compound<int*>::type, std::true_type>::value, "type == true_type");
static_assert(std::is_compound<int*>() == true, "is_compound<int*>() == true");

static_assert(std::is_compound<void>::value == false, "value == false, void is not compound");
static_assert(std::is_same<std::is_compound<void>::value_type, bool>::value, "value_type == bool");
static_assert(std::is_same<std::is_compound<void>::type, std::false_type>::value, "type == false_type");
static_assert(std::is_compound<void>() == false, "is_compound<void>() == false");

enum e{};
class c{};
union u{};
static_assert(std::is_compound<e>::value == true, "enum is compound");
static_assert(std::is_compound<c>::value == true, "class is compound");
static_assert(std::is_compound<u>::value == true, "union is compound");
static_assert(std::is_compound<int* const volatile>::value == true, "int* const volatile is compound");
static_assert(std::is_compound<int[1]>::value == true, "int[1] is compound");
static_assert(std::is_compound<int&>::value == true, "int& is not compound");
static_assert(std::is_compound<int ()>::value == true, "int () is not compound");
static_assert(std::is_compound<std::nullptr_t>::value == false, "std::nullptr_t is not compound");

int main(){}

出力

バージョン

言語

  • C++11

処理系

  • GCC: 4.3.4, 4.5.3, 4.6.2, 4.7.0
  • Visual C++: 2008 (std::tr1), 2010, 2012, 2013, 2015
    • 2012までは、テンプレート実引数にstd::nullptr_tやそのCV修飾を渡した場合、誤ってtrue_typeからの派生になっている。

備考

上の例でコンパイラによってはエラーになる。GCC 4.3.4, 4.5.3, Visual C++ 2010 は integral_constantoperator bool を持っていないためエラーになる。

参照