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

std::is_standard_layout

Defined in header <type_traits>

?

?

template< class T > struct is_standard_layout;

?

(since C++11)

如果T是标准布局类型%28,即标量类型、标准布局类或此类类型/类的数组(可能是cv限定%29)提供成员常量。value平等true.对于任何其他类型,valuefalse...

阿标准布局类是满足以下条件的类StandardLayoutType...

如果std::remove_all_extents_t<T>是不完整的类型,而不是%28可能是cv-合格%29。void...

模板参数

T

-

a type to check

辅助变量模板

template< class T > inline constexpr bool is_standard_layout_v = is_standard_layout<T>::value;

?

(since C++17)

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

成员常数

value static

true if T is a standard-layout 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>

注记

指向标准布局类的指针可以通过重新解释而转换为%28。[医]将%29转换为指向其第一个非静态数据成员的指针,反之亦然。

如果标准布局联合包含两个或多个标准布局结构,则允许检查它们的公共初始部分。

offsetof只能与标准布局类一起使用。

二次

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

二次

产出:

二次

代码语言:javascript
复制
true
false
false

二次

另见

is_trivially_copyable (C++11)

checks if a type is trivially copyable (class template)

is_pod (C++11)

checks if a type is plain-old data (POD) type (class template)

offsetof

byte offset from the beginning of a standard-layout type to specified member (function macro)

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

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

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com