Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ Moderated > Re: How to conv...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 6 of 13 Topic 9564 of 9823
Post > Topic >>

Re: How to convert a pointer to member function type to a const member one

by mcostalba <mcostalba@[EMAIL PROTECTED] > May 1, 2008 at 01:43 PM

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! ]
 




 13 Posts in Topic:
How to convert a pointer to member function type to a const memb
mcostalba <mcostalba@[  2008-04-30 10:38:30 
Re: How to convert a pointer to member function type to a const
nickf3 <nickf3@[EMAIL   2008-04-30 17:04:17 
Re: How to convert a pointer to member function type to a const
smolensky@[EMAIL PROTECTE  2008-04-30 21:54:58 
Re: How to convert a pointer to member function type to a const
"Devdatt Lad" &  2008-04-30 21:54:37 
Re: How to convert a pointer to member function type to a const
Greg Herlihy <greghe@[  2008-04-30 22:17:24 
Re: How to convert a pointer to member function type to a const
mcostalba <mcostalba@[  2008-05-01 13:43:23 
Re: How to convert a pointer to member function type to a const
"Roman.Perepelitsa@[  2008-05-05 07:09:51 
Re: How to convert a pointer to member function type to a const
mcostalba <mcostalba@[  2008-05-06 00:57:14 
Re: How to convert a pointer to member function type to a const
"Roman.Perepelitsa@[  2008-05-06 08:21:31 
Re: How to convert a pointer to member function type to a const
mcostalba <mcostalba@[  2008-05-06 12:47:31 
Re: How to convert a pointer to member function type to a const
dizzy <dizzy@[EMAIL PR  2008-05-07 11:04:35 
Re: How to convert a pointer to member function type to a const
"Roman.Perepelitsa@[  2008-05-07 11:04:05 
Re: How to convert a pointer to member function type to a const
mcostalba <mcostalba@[  2008-05-07 18:33:58 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Thu Jul 24 1:49:16 CDT 2008.