std::add_pointer 非静态成员函数的实现
std::add_pointer implementation for non-static member functions
此问题是 有关 std::add_pointer 实施的问题的后续问题
之下
有以下参考:
Otherwise (if T is a cv- or ref-qualified function type), provides the
member typedef type which is the type T.
根据阅读 Non-static member functions: const-, volatile-, and ref-qualified member functions,我的理解是对于具有给定 cv
and/or ref
资格的非静态成员函数,
a) 函数的 cv
限定也适用于 this
指针,在函数范围内
b) 函数的ref
限定不适用于函数范围内的this
指针
鉴于此,为什么 std::add_pointer
不能提供成员 typedef
type
T*
在具有 [=11 的非静态成员函数的情况下=]或ref
资格?
根据 [dcl.ptr]/4:
[ Note: Forming a pointer to reference type is ill-formed; see
[dcl.ref]. Forming a function pointer type is ill-formed if the
function type has cv-qualifiers or a ref-qualifier; see
[dcl.fct]. Since the address of a bit-field cannot be taken, a
pointer can never point to a bit-field. — end
note ]
您想象的指向cv限定函数的指针类型实际上是不存在的。因此,std::add_pointer
不能产生这样的类型:)
无法形成非静态成员函数类型。这种东西是不存在的。
struct T {
int func() const;
};
func
没有类型。您永远不能将其单独用作表达式。
using mf = int (T::*)() const;
mf myfunc = &T::func;
mf
是指向成员函数类型的指针。它不是函数类型;指向非静态成员(包括成员函数)的指针是数据,而不是函数。
成员函数的 cv 或 ref 限定不限定函数类型,它不存在,而是隐式 "this" 参数的类型。
您引用的段落仅适用于非成员函数或静态成员函数。
此问题是 有关 std::add_pointer 实施的问题的后续问题
之下有以下参考:
Otherwise (if T is a cv- or ref-qualified function type), provides the member typedef type which is the type T.
根据阅读 Non-static member functions: const-, volatile-, and ref-qualified member functions,我的理解是对于具有给定 cv
and/or ref
资格的非静态成员函数,
a) 函数的 cv
限定也适用于 this
指针,在函数范围内
b) 函数的ref
限定不适用于函数范围内的this
指针
鉴于此,为什么 std::add_pointer
不能提供成员 typedef
type
T*
在具有 [=11 的非静态成员函数的情况下=]或ref
资格?
根据 [dcl.ptr]/4:
[ Note: Forming a pointer to reference type is ill-formed; see [dcl.ref]. Forming a function pointer type is ill-formed if the function type has cv-qualifiers or a ref-qualifier; see [dcl.fct]. Since the address of a bit-field cannot be taken, a pointer can never point to a bit-field. — end note ]
您想象的指向cv限定函数的指针类型实际上是不存在的。因此,std::add_pointer
不能产生这样的类型:)
无法形成非静态成员函数类型。这种东西是不存在的。
struct T {
int func() const;
};
func
没有类型。您永远不能将其单独用作表达式。
using mf = int (T::*)() const;
mf myfunc = &T::func;
mf
是指向成员函数类型的指针。它不是函数类型;指向非静态成员(包括成员函数)的指针是数据,而不是函数。
成员函数的 cv 或 ref 限定不限定函数类型,它不存在,而是隐式 "this" 参数的类型。
您引用的段落仅适用于非成员函数或静态成员函数。