std:: is_layout_compatible
| Type traits | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Compile-time rational arithmetic | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Compile-time integer sequences | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
(C++14)
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
헤더 파일에 정의됨
<type_traits>
|
||
|
template
<
class
T,
class
U
>
struct is_layout_compatible ; |
(C++20부터) | |
만약
T
와
U
가
layout-compatible
타입인 경우, 멤버 상수
value
를
true
로 제공합니다. 그렇지 않으면
value
는
false
입니다.
모든 타입은 객체 타입이 아니더라도, 자신의 모든 cv 한정 버전과 레이아웃 호환됩니다.
만약
T
또는
U
가 완전한 타입이 아니거나, (cv-qualified일 수 있는)
void
, 또는 알려지지 않은 경계의 배열인 경우, 동작은 정의되지 않습니다.
템플릿의 인스턴스화가 직접적 또는 간접적으로 불완전한 타입에 의존하고, 해당 타입이 가상적으로 완성되었을 때 인스턴스화 결과가 달라질 수 있는 경우, 그 동작은 정의되지 않습니다.
프로그램이
std::is_layout_compatible
또는
std::is_layout_compatible_v
에 대한 특수화를 추가하는 경우, 그 동작은 정의되지 않습니다.
목차 |
헬퍼 변수 템플릿
|
template
<
class
T,
class
U
>
constexpr bool is_layout_compatible_v = is_layout_compatible < T, U > :: value ; |
(C++20부터) | |
std:: integral_constant 에서 상속됨
멤버 상수
|
value
[static]
|
true
만약
T
와
U
가 레이아웃 호환 가능한 경우,
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 > |
참고 사항
부호 있는 정수 타입과 그에 대응하는 부호 없는 타입은 레이아웃 호환되지 않습니다. char 는 signed char 와도 unsigned char 와도 레이아웃 호환되지 않습니다.
유사한 타입 은 최상위 cv-한정자를 무시한 후 동일한 타입이 아닌 경우 레이아웃 호환되지 않습니다.
열거형 타입과 그 기반 타입은 레이아웃 호환되지 않습니다.
레이아웃 호환적이지만 요소 타입이 다른 배열 타입들(cv 한정자는 무시)은 길이가 같더라도 레이아웃 호환적이지 않습니다.
| 기능 테스트 매크로 | 값 | 표준 | 기능 |
|---|---|---|---|
__cpp_lib_is_layout_compatible
|
201907L
|
(C++20) |
std::is_layout_compatible
|
예제
#include <iomanip> #include <iostream> #include <type_traits> struct Foo { int x; char y; }; struct FooNua { int x; [[no_unique_address]] char y; }; class Bar { const int u = 42; volatile char v = '*'; }; enum E0 : int {}; enum class E1 : int {}; static_assert ( std::is_layout_compatible_v<const void, volatile void> == true and std::is_layout_compatible_v<Foo, Bar> == true and std::is_layout_compatible_v<Foo[2], Bar[2]> == false and std::is_layout_compatible_v<int, E0> == false and std::is_layout_compatible_v<E0, E1> == true and std::is_layout_compatible_v<long, unsigned long> == false and std::is_layout_compatible_v<char*, const char*> == false and std::is_layout_compatible_v<char*, char* const> == true and std::is_layout_compatible_v<Foo, FooNua> == false // Note [1] ); // [1] MSVC erroneously fails this assert int main() {}
참고 항목
|
(C++11)
|
타입이
standard-layout
타입인지 검사합니다
(클래스 템플릿) |