|
Boost : |
From: Paul Mensonides (pmenso57_at_[hidden])
Date: 2003-02-04 17:10:39
Daniel Frey wrote:
>> Yes, I worded that incorrectly. I should have said: are you thinking
>> that the above will match
>>
>> int (X::*pf)(long, double) const;
>
> I'm not absolutely sure, but I think that this creates a non-const
> pointer to a const member function. As far as I understand it, this is
> equivalent to:
>
> typedef int ft( long, double ) const;
> ft X::* pf;
Yes, the type of 'pf' is:
int (X::*)(long, double) const;
> To create something that matches to above specialization, you have to
> do something like this:
>
> ft X::* const cpf;
I might be misunderstanding you, but the above does not match the type "int
(X::*)(long, double) const." E.g. if I have this template:
#include <iostream>
template<class> struct test {
enum { value = false };
};
template<class R, class C> struct test<R C::* const> {
enum { value = true };
};
struct X { };
typedef int (X::* Y)(long, double) const;
int main() {
std::cout
<< test<Y>::value // false
<< '\n'
<< test<const Y>::value // true
<< &std::endl;
return 0;
}
In other words, "R C::* const" is a constant pointer-to-member, not a
pointer-to-const-member, and certainly not a pointer-to-const-member-function.
It *can* match a const-pointer-to-const-member-function, but then the
const-qualification of the member function would be hidden in the 'R' type.
> Anyway, what is the point of this? I specialize for a pointer and
> pointers can be cv-qualified, thus to be complete I have to provide
> specializations for all cv-versions, haven't I?
That is what I assumed that you meant when I saw those specializations. At this
point, I'm not sure, so I'm just clarifying that these two types are _not_
equivalent:
typedef void (X::* _1)() const;
typedef void F();
typedef F X::* const _2;
Type #1 is a pointer-to-const-qualified-member-function. Type #2 is a
const-pointer-to-unqualified-member-function.
As I said, I may be misunderstanding you. If so, just consider it a
clarification for everyone else. As is, the four specializations that you
provided with catch any unqualified (first one) or qualified (other three)
pointer-to-member. The nested call to 'is_function' should yield true if the
pointed-to type a function type (cv-qualified or otherwise).
Paul Mensonides
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk