On 1 Mag, 06:17, Greg Herlihy <gre...@[EMAIL PROTECTED]
> wrote:
>
> I'm assuming that you want to "synthesize" a member function pointer
> type for a const class method - given a member function pointer for an
> equivalent non-const class method.
Yes, this is similar to what I have to do, actually I have to do the
contrary: detect pointer to const member functions.
>
> // General helper template declared - but not defined
>
> template <class T>
> struct AddConstToMemberFunctionPtr;
>
> // specialized for member function pointers only
>
> template <class R, class T, class P>
> struct AddConstToMemberFunctionPtr<R (T::*)(P)>
> {
> typedef R (T::*type)(P) const;
> };
>
This works but is not "general". It works only for pointer to member
with one argument.
I try to explain better the problem.
I have to detect if a functor type Fun has a given signature Sig, i.e.
if Fun::operator() has a signature Sig
What I have written til now is:
/* Check if a function/functor Fun has a given signature Sig */
template<typename Fun, typename Sig>
struct is_compatible
{
/* Check for a function */
template<class U> static
yes_type check(typename enable_if<is_same<U, Sig> >::type*);
/* Check for a functor */
template<class U, Sig U::*> struct helper;
template<class U> static
yes_type check(helper<U, &U::operator()>*);
/* Default */
template<class U> static no_type check(...);
typedef typename boost::remove_pointer<Fun>::type F;
static bool const
value = (sizeof(check<F>(0)) == sizeof(yes_type));
};
Then
is_compatible<Fun, Sig>::value
It's true iff Fun is a function or functor with signature Sig
It works nicely for any signature, i.e. for any argument number and
type, but it missed const members because
template<class U, Sig U::*> struct helper;
misses them. BTW writing
template<class U, Sig U::* const> struct helper;
does not im****ve anything.
I hope this is more clear on what I would need.
Thanks for your help
Marco
--
[ See http://www.gotw.ca/resources/clcm.htm
for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]


|