首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::is_empty

Defined in header <type_traits>

?

?

template< class T > struct is_empty;

?

(since C++11)

如果T是一个空类型%28,也就是说,除了大小为0的位字段之外,没有任何非静态数据成员的非联合类类型,没有虚拟函数,没有虚拟基类,也没有非空基类%29,提供了成员常量。value平等true.对于任何其他类型,valuefalse...

如果T是非工会类类型,T应该是一个完整的类型;否则,该行为是未定义的。

模板参数

T

-

a type to check

辅助变量模板

template< class T > inline constexpr bool is_empty_v = is_empty<T>::value;

?

(since C++17)

继承自STD:积分[医]常量

成员常数

value static

true if T is an empty class type , false otherwise (public static member constant)

成员函数

operator bool

converts the object to bool, returns value (public member function)

operator() (C++14)

returns value (public member function)

成员类型

Type

Definition

value_type

bool

type

std::integral_constant<bool, value>

注记

从空基类继承通常不会增加类的大小,原因是空基优化...

std::is_empty<T>所有其他类型的特征都是空类。

二次

代码语言:javascript
复制
#include <iostream>
#include <type_traits>
 
struct A {};
 
struct B {
    int m;
};
 
struct C {
    virtual ~C();
};
 
int main()
{
    std::cout << std::boolalpha;
    std::cout << std::is_empty<A>::value << '\n';
    std::cout << std::is_empty<B>::value << '\n';
    std::cout << std::is_empty<C>::value << '\n';
}

二次

产出:

二次

代码语言:javascript
复制
true
false
false

二次

另见

is_class (C++11)

checks if a type is a non-union class type (class template)

代码语言:txt
复制
 ? cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com