std:: is_corresponding_member
| Type traits | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Compile-time rational arithmetic | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Compile-time integer sequences | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
(C++14)
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
ヘッダーで定義
<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 {}; // 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() {}
関連項目
|
(C++11)
|
型が
standard-layout
型であるかどうかをチェックする
(クラステンプレート) |
|
(C++20)
|
2つの型が
layout-compatible
であるかどうかをチェックする
(クラステンプレート) |
|
(C++11)
|
型が非静的メンバオブジェクトポインタであるかどうかをチェックする
(クラステンプレート) |