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
不是
标准布局类型
,或者
M1
或
M2
不是对象类型,或者
mp
或
mq
等于
nullptr
,则结果始终为
false
。
目录 |
参数
| mp, mq | - | 待检测的成员指针 |
返回值
如果
mp
和
mq
指向
S1
和
S2
公共初始序列中的对应成员,则为
true
;否则为
false
。
注释
指向成员表达式
&
S
::
m
的类型并不总是
M S
::
*
,因为
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() {}
参见
|
(C++11)
|
检查类型是否为
标准布局
类型
(类模板) |
|
(C++20)
|
检查两个类型是否为
布局兼容
(类模板) |
|
(C++11)
|
检查类型是否为非静态成员对象指针
(类模板) |