std:: is_pointer_interconvertible_with_class
| Type traits | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Compile-time rational arithmetic | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Compile-time integer sequences | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
(C++14)
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
헤더에 정의됨
<type_traits>
|
||
|
template
<
class
S,
class
M
>
constexpr bool is_pointer_interconvertible_with_class ( M S :: * mp ) noexcept ; |
(C++20부터) | |
타입
S
의 객체
s
가 주어졌을 때,
s.
*
mp
가
s
의 하위 객체를 참조하는지와
s
가 해당 하위 객체
s.
*
mp
와
포인터 상호 변환 가능
한지 판단합니다.
S
가
완전한 타입
이 아닌 경우 프로그램은 형식 오류를 가집니다.
만약
S
가
StandardLayoutType
이 아니거나,
M
가 객체 타입이 아니거나,
mp
가
nullptr
인 경우, 결과는 항상
false
입니다.
목차 |
매개변수
| mp | - | 감지할 멤버 포인터 |
반환값
true
만약
s.
*
mp
가
s
의 하위 객체를 참조하고
s
가 해당 하위 객체
s.
*
mp
와 포인터 상호 변환 가능한 경우, 그렇지 않으면
false
를 반환합니다. 여기서
s
는
S
타입의 객체입니다.
참고 사항
멤버-대-포인터 표현식의 타입
&
S
::
m
는 항상
M S
::
*
가 아닙니다. 여기서
m
이
M
타입일 때,
m
이
S
의 기본 클래스로부터 상속된 멤버일 수 있기 때문입니다. 잠재적으로 예상치 못한 결과를 피하기 위해 템플릿 인자를 명시적으로 지정할 수 있습니다.
만약
mp
가
M S
::
*
타입의 값으로 존재하여
std
::
is_pointer_interconvertible_with_class
(
mp
)
==
true
인 경우,
reinterpret_cast
<
M
&
>
(
s
)
는 잘 정의된 결과를 가지며
s.
*
mp
와 동일한 하위 객체를 참조합니다. 여기서
s
는
S
타입의 유효한 lvalue입니다.
일반적인 플랫폼에서,
mp
의 비트 패턴은
std
::
is_pointer_interconvertible_with_class
(
mp
)
==
true
인 경우 모두 0입니다.
| 기능 테스트 매크로 | 값 | 표준 | 기능 |
|---|---|---|---|
__cpp_lib_is_pointer_interconvertible
|
201907L
|
(C++20) |
포인터 상호 변환 특성:
|
예제
#include <type_traits> struct Foo { int x; }; struct Bar { int y; }; struct Baz : Foo, Bar {}; // 표준 레이아웃이 아님 static_assert( not std::is_same_v<decltype(&Baz::x), int Baz::*> ); static_assert( std::is_pointer_interconvertible_with_class(&Baz::x) ); static_assert( not std::is_pointer_interconvertible_with_class<Baz, int>(&Baz::x) ); int main() { }
참고 항목
|
(C++11)
|
타입이
standard-layout
타입인지 검사합니다
(클래스 템플릿) |
|
(C++11)
|
타입이 비정적 멤버 객체 포인터인지 검사합니다
(클래스 템플릿) |