Namespaces
Variants

std:: is_corresponding_member

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 S1, class S2, class M1, class M2 >
constexpr bool is_corresponding_member ( M1 S1 :: * mp, M2 S2 :: * mq ) noexcept ;
(C++20부터)

mp mq S1 S2 공통 초기 시퀀스 에서 대응하는 멤버를 참조하는지 여부를 결정합니다. S1 또는 S2 중 하나가 불완전한 타입 인 경우 프로그램은 형식에 맞지 않습니다.

만약 S1 또는 S2 StandardLayoutType 이 아니거나, M1 또는 M2 가 객체 타입이 아니거나, mp 또는 mq nullptr 인 경우, 결과는 항상 false 입니다.

목차

매개변수

mp, mq - 감지할 멤버 포인터

반환값

true 만약 mp mq S1 S2 의 공통 초기 시퀀스에서 해당 멤버들을 참조하는 경우, 그렇지 않으면 false .

참고 사항

멤버-대-포인터 표현식의 타입 & S :: m 는 항상 M S :: * 가 아닙니다. 여기서 m 이 타입 M 을 가지는 경우, m S 의 기본 클래스로부터 상속된 멤버일 수 있기 때문입니다. 잠재적으로 예상치 못한 결과를 피하기 위해 템플릿 인자를 명시적으로 지정할 수 있습니다.

예제

#include <type_traits>
struct Foo
{
    int x;
    double d;
};
struct Bar
{
    int y;
    double z;
};
struct Baz : Foo, Bar {}; // 표준 레이아웃 아님
static_assert(
    std::is_same_v<decltype(&Baz::x), int Foo::*> == true &&
    std::is_same_v<decltype(&Baz::y), int Bar::*> == true &&
    std::is_corresponding_member(&Foo::x, &Bar::y) == true &&
    std::is_corresponding_member(&Foo::d, &Bar::z) == true &&
    std::is_corresponding_member(&Baz::x, &Baz::y) == true &&
    std::is_corresponding_member<Baz, Baz, int, int>(&Baz::x, &Baz::y) == false
);
int main() {}

참고 항목

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