Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

std::add_pointer implementation for non-static member functions

This question is a follow-up of A question regarding the implementation of std::add_pointer

Under std::add_pointer

there is the following reference:

Otherwise (if T is a cv- or ref-qualified function type), provides the member typedef type which is the type T.

Based on reading Non-static member functions: const-, volatile-, and ref-qualified member functions, my understanding is that a for a non-static member function with given cvand/or ref qualification,

a) the cv qualification of the function applies to the this pointer as well, within the scope of the function

b) the ref qualification of the function does not apply to the this pointer within the scope of the function

Given this, why is it that std::add_pointer cannot provide the member typedef type T* in the case of a non-static member function with cv or ref qualification?

like image 832
Vinod Avatar asked Nov 07 '22 14:11

Vinod


1 Answers

Per [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 ]

The pointer-to-cv-qualified-function type you are imagining is actually nonexistent. Therefore, std::add_pointer cannot produce such a type :)

like image 156
L. F. Avatar answered Nov 15 '22 05:11

L. F.