Namespaces
Variants

std:: is_standard_layout

From cppreference.net
Metaprogramming library
Type traits
Type categories
(C++11)
(C++11) ( DR* )
Type properties
(C++11)
(C++11)
(C++14)
(C++11) (deprecated in C++26)
is_standard_layout
(C++11)
(C++11) ( until C++20* )
(C++11) (deprecated in C++20)
(C++11)
Type trait constants
Metafunctions
(C++17)
Supported operations
Relationships and property queries
Type modifications
Type transformations
(C++11) (deprecated in C++23)
(C++11) (deprecated in C++23)
(C++11)
(C++11) ( until C++20* ) (C++17)

Compile-time rational arithmetic
Compile-time integer sequences
헤더 파일에 정의됨 <type_traits>
template < class T >
struct is_standard_layout ;
(C++11부터)

std::is_standard_layout UnaryTypeTrait 입니다.

만약 T standard-layout type 인 경우, 멤버 상수 value true 로 설정합니다. 다른 모든 타입에 대해서는 value false 입니다.

만약 std:: remove_all_extents_t < T > 가 불완전한 타입이고 (가능한 cv-qualified) void 가 아닌 경우, 동작은 정의되지 않습니다.

프로그램이 std::is_standard_layout 또는 std::is_standard_layout_v 에 대한 특수화를 추가하는 경우, 그 동작은 정의되지 않습니다.

목차

템플릿 매개변수

T - 확인할 타입

헬퍼 변수 템플릿

template < class T >
constexpr bool is_standard_layout_v = is_standard_layout < T > :: value ;
(C++17 이후)

std:: integral_constant 로부터 상속됨

멤버 상수

value
[static]
true 만약 T 가 표준 레이아웃 타입이면, false 그렇지 않으면
(public static member constant)

멤버 함수

operator bool
객체를 bool 로 변환, value 반환
(public member function)
operator()
(C++14)
value 반환
(public member function)

멤버 타입

타입 정의
value_type bool
type std:: integral_constant < bool , value >

참고 사항

표준 레이아웃 클래스에 대한 포인터는 ( reinterpret_cast 를 사용하여) 해당 클래스의 첫 번째 비정적 데이터 멤버에 대한 포인터로 변환될 수 있으며 (참조: empty base optimization ) 그 역도 성립합니다.

표준 레이아웃 공용체가 두 개 이상의 표준 레이아웃 구조체를 포함하는 경우, 이들의 공통 초기 부분을 검사하는 것이 허용됩니다.

매크로 offsetof 는 표준 레이아웃 클래스에서만 사용 가능하도록 보장됩니다.

예제

#include <type_traits>
struct A { int m; };
static_assert(std::is_standard_layout_v<A> == true);
class B: public A { int m; };
static_assert(std::is_standard_layout_v<B> == false);
struct C { virtual void foo(); };
static_assert(std::is_standard_layout_v<C> == false);
int main() {}

결함 보고서

다음의 동작 변경 결함 보고서들은 이전에 발표된 C++ 표준에 소급 적용되었습니다.

DR 적용 대상 게시된 동작 올바른 동작
LWG 2015 C++11 T 는 경계를 알 수 없는 불완전
클래스 타입의 배열일 수 있음
이 경우 동작은
정의되지 않음

참고 항목

타입이 trivially copyable인지 검사합니다
(class template)
(C++11) (deprecated in C++20)
타입이 plain-old data (POD) 타입인지 검사합니다
(class template)
standard-layout 타입의 시작부터 지정된 멤버까지의 바이트 오프셋
(function macro)