std::is_compound

定义于头文件 <type_traits>
template< class T >
struct is_compound;
(C++11 起)

T 是复合类型(即数组、函数、对象指针、函数指针、成员对象指针、成员函数指针、引用、类、联合体或枚举,含任何 cv 限定变体),则提供等于 true 的成员常量 value 。对于任何其他类型, valuefalse

目录

模板形参

T - 要检查的类型

辅助变量模板

template< class T >
inline constexpr bool is_compound_v = is_compound<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>

注意

复合类型是从基础类型构造的类型。任何 C++ 类型为基础或复合之一。

可能的实现

template< class T >
struct is_compound : std::integral_constant<bool, !std::is_fundamental<T>::value> {};

示例

#include <iostream>
#include <type_traits>
 
int main() {
    class cls {};
    std::cout << (std::is_compound<cls>::value
                     ? "T is compound"
                     : "T is not a compound") << '\n';
    std::cout << (std::is_compound<int>::value
                     ? "T is compound"
                     : "T is not a compound") << '\n';
}

输出:

T is compound
T is not a compound

参阅

检查是否是基础类型
(类模板)
(C++11)
检查类型是否为标量类型
(类模板)
(C++11)
检查是否是对象类型
(类模板)
(C++11)
检查类型是否是数组类型
(类模板)

版本历史

  • (当前 | 先前 2017年11月18日 (六) 21:53Fruderica讨论 | 贡献 . . (1,695字节) (0). . (形参/辅助) (撤销)
  • 当前 | 先前 2017年7月25日 (二) 05:43Fruderica讨论 | 贡献. . (1,695字节) (-464). . (撤销)
  • 当前 | 先前 2014年10月26日 (日) 18:13P12bot讨论 | 贡献 . . (2,159字节) (0). . (Fix some translations) (撤销)
  • 当前 | 先前 2013年7月2日 (二) 11:40P12bot讨论 | 贡献 . . (2,159字节) (-114). . (Use {{lc}}. Update links. Various fixes.) (撤销)
  • 当前 | 先前 2012年11月2日 (五) 16:45P12bot讨论 | 贡献 . . (2,273字节) (+233). . (r2.7.3) (机器人添加:de, en, es, fr, it, ja, pt, ru) (撤销)
  • 当前 | 先前 2012年10月27日 (六) 11:38P12讨论 | 贡献 . . (2,040字节) (0). . (1个修订: Translate from the English version) (撤销)
  • 当前 | 先前 2012年10月26日 (五) 06:00TranslationBot讨论 | 贡献. . (2,040字节) (-30). . (Translated from the English version using Google Translate) (撤销)
  • 当前 | 先前 2012年10月26日 (五) 03:33P12讨论 | 贡献 . . (2,070字节) (0). . (1个修订: Translate from the English version) (撤销)
  • 当前 | 先前) 2012年10月25日 (四) 12:00TranslationBot讨论 | 贡献. . (2,070字节) (+2,070). . (Translated from the English version using Google Translate)