Namespaces
Variants

std:: is_pointer_interconvertible_with_class

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)
(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 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() { }

참고 항목

타입이 standard-layout 타입인지 검사합니다
(클래스 템플릿)
타입이 비정적 멤버 객체 포인터인지 검사합니다
(클래스 템플릿)