types_is_pointer_interconvertible_with_class
types_is_pointer_interconvertible_with_class (클래스와 포인터 상호 변환 가능 여부 판별)
이 페이지는 C++20에서 도입된 std::is_pointer_interconvertible_with_class 함수 템플릿에 대해 설명해요. 이 함수는 주어진 객체의 멤버를 가리키는 포인터-투-멤버가 그 객체와 포인터 상호 변환 가능(pointer-interconvertible)한 하위 객체를 가리키는지 판별해요. constexpr이며 noexcept로 지정되어 컴파일 타임에 사용할 수 있어요.
출처: cppreference
본문
Defined in header <type_traits> |
||
|---|---|---|
template < class S , class M > constexpr bool is_pointer_interconvertible_with_class ( M S ::* mp ) noexcept ; |
(since C++20) |
형식 S의 객체 s가 주어졌을 때, s.*mp가 s의 하위 객체를 가리키고 s가 그 하위 객체 s.*mp와 포인터 상호 변환 가능한지 여부를 판별해요. S가 완전한 형식(complete type)이 아니면 프로그램은 ill-formed예요.
S가 StandardLayoutType이 아니거나, M이 객체 형식이 아니거나, mp가 nullptr과 같으면 결과는 항상 false예요.
Parameters
| mp | - | 검사할 멤버 포인터 |
|---|
Return value
s가 형식 S의 객체일 때, s.*mp가 s의 하위 객체를 가리키고 s가 그 하위 객체 s.*mp와 포인터 상호 변환 가능하면 true, 그렇지 않으면 false를 반환해요.
Notes
멤버 포인터 식 &S::m의 형식은 항상 M S::*가 아니에요. 여기서 m은 형식 M이고, m이 S의 기본 클래스에서 상속된 멤버일 수 있기 때문이에요. 잠재적으로 놀라운 결과를 피하려면 템플릿 인자를 명시적으로 지정할 수 있어요.
M S::* 형식의 값 mp가 존재해서 std::is_pointer_interconvertible_with_class(mp) == true라면, reinterpret_cast<M&>(s)는 잘 정의된 결과를 가지며 s가 형식 S의 유효한 lvalue일 때 s.*mp와 같은 하위 객체를 가리켜요.
일반적인 플랫폼에서 std::is_pointer_interconvertible_with_class(mp) == true이면 mp의 비트 패턴은 모두 0이에요.
| Feature-test macro | 값 | 표준 | 기능 |
|---|---|---|---|
__cpp_lib_is_pointer_interconvertible |
201907L |
(C++20) | 포인터 상호 변환 가능 특성: std::is_pointer_interconvertible_base_of, std::is_pointer_interconvertible_with_class |
Example
#include <type_traits>
struct Foo { int x; };
struct Bar { int y; };
struct Baz : Foo, Bar {}; // not standard-layout
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() { }
See also
is_standard_layout (C++11) |
형식이 표준 레이아웃 형식인지 검사해요 (클래스 템플릿) [edit] |
|---|---|
is_member_object_pointer (C++11) |
형식이 비정적 멤버 객체 포인터인지 검사해요 (클래스 템플릿) [edit] |