A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://en.cppreference.com/w/cpp/algorithm/../ranges/../types/is_corresponding_member.html below:

std::is_corresponding_member - cppreference.com

template< class S1, class S2, class M1, class M2 >
constexpr bool is_corresponding_member( M1 S1::* mp, M2 S2::* mq ) noexcept;

(since C++20)

Determines whether mp and mq refer corresponding members in the common initial sequence of S1 and S2. The program is ill-formed if either S1 or S2 is an incomplete type.

If either S1 or S2 is not a StandardLayoutType, or either M1 or M2 is not an object type, or either mp or mq is equal to nullptr, the result is always false.

[edit] Parameters mp, mq - pointers-to-member to detect [edit] Return value

true if mp and mq refer corresponding members in the common initial sequence of S1 and S2, otherwise false.

[edit] Notes

The type of a pointer-to-member expression &S::m is not always M S::*, where m is of type M, because m may be a member inherited from a base class of S. The template arguments can be specified in order to avoid potentially surprising results.

[edit] Example
#include <type_traits>
 
struct Foo
{
    int x;
    double d;
};
 
struct Bar
{
    int y;
    double z;
};
 
struct Baz : Foo, Bar {}; // not standard-layout
 
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() {}
[edit] See also

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4