[英]Type of a removed pointer to function member
The type of: 类型:
std::remove_pointer<int(*)(int)>::type
is int(int)
. 是
int(int)
。 This code: 这段代码:
#include <iostream>
#include <type_traits>
using namespace std;
int main()
{
cout << boolalpha;
cout << is_same<remove_pointer<int(*)(int)>, int(int)>::value;
cout << endl;
}
prints 'true'. 打印'true'。 But, what is the (written) type of a "function member"?
但是,“职能成员”的(书面)类型是什么?
#include <iostream>
#include <type_trais>
using namespace std;
struct A {};
int main()
{
cout << boolalpha;
cout << is_same<remove_pointer<int(A::*)(int)>, int(int)>::value;
cout << endl;
}
returns false
. 返回
false
。 And something like int A::(int)
throws a compilation error (invalid type). 像
int A::(int)
这样的东西会引发编译错误(无效类型)。
A pointer-to-member is not a pointer. 指向成员的指针不是指针。
remove_pointer
won't change the type. remove_pointer
不会更改类型。
It goes like this: A non-member type is either an object or a function type: 它是这样的:非成员类型是对象或函数类型:
T = int; // object type
T = double(char, bool) // function type
For non-static class members, you can only have pointer-to-member types. 对于非静态类成员,您只能具有指向成员的指针类型。 Those are of the form:
格式如下:
class Foo;
PM = U Foo::*; // pointer to member type
The question is what U
is: 问题是
U
是什么:
U = int => PM = int Foo::* // pointer-to-member-object
U = double(char, bool) => PM = double (Foo::*)(char, bool) // pointer-to-member-function
A "pointer-to-member" is not a pointer, and so you cannot "remove the pointer" from it. “成员指针”不是指针,因此您不能从中“删除指针”。 At best you can get the underlying type, ie go from
PM = U Foo::*
to U
. 充其量可以得到基础类型,即从
PM = U Foo::*
到U
To my knowledge, no such trait exists, but it is easily concocted: 据我所知,没有这样的特征,但是很容易炮制:
template <typename> struct remove_member_pointer;
template <typename U, typename F> struct remove_member_pointer<U F::*>
{
typedef U member_type;
typedef F class_type;
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.