定义于头文件
<type_traits>
|
||
template< class T >
struct is_union; |
(C++11 起) | |
检查 T
是否为联合体类型。若 T
为联合体类型,则提供等于 true 的成员常量 value
。否则 value
,等于 false 。
目录 |
T | - | 要检查的类型 |
template< class T >
inline constexpr bool is_union_v = is_union<T>::value; |
(C++17 起) | |
value
[静态]
|
若 T 为联合体类型则为 true ,否则为 false (公开静态成员常量) |
operator bool
|
转换对象为 bool ,返回 value (公开成员函数) |
operator()
(C++14)
|
返回 value (公开成员函数) |
类型 | 定义 |
value_type
|
bool
|
type
|
std::integral_constant<bool, value> |
#include <iostream> #include <type_traits> struct A {}; typedef union { int a; float b; } B; struct C { B d; }; int main() { std::cout << std::boolalpha; std::cout << std::is_union<A>::value << '\n'; std::cout << std::is_union<B>::value << '\n'; std::cout << std::is_union<C>::value << '\n'; std::cout << std::is_union<int>::value << '\n'; }
输出:
false true false false
(C++11)
|
检查类型是否非联合类类型 (类模板) |