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 10 of 13 Topic 9564 of 9807
Post > Topic >>

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

by mcostalba <mcostalba@[EMAIL PROTECTED] > May 6, 2008 at 12:47 PM

On 6 Mag, 16:21, "Roman.Perepeli...@[EMAIL PROTECTED]
"
<Roman.Perepeli...@[EMAIL PROTECTED]
> wrote:
>
>
> Alexandre Courpron modified is_call_possible to create
> is_exact_call_possible. You can find implementation
here:http://groups.google.co.uk/group/comp.lang.c++.moderated/browse_threa...

I have quickly checked the link and it surely deserves a deeper read
when I found a bit of time.

Anyhow here is my much simpler solution...so simple that is probably
broken in some way, but I cannot find where:

    /* Check if a function/functor Fun has a given signature Sig */
     template<typename Fun, typename Sig>
     struct is_compatible
     {
         typedef typename boost::remove_pointer<Fun>::type F;

         /* Build pointer_to_member types from the given signature */
         typedef typename pointer_to_member<is_function<F>::value, F,
Sig>::type ptm;
         typedef typename pointer_to_member<is_function<F>::value, F,
Sig>::const_type ptm_const;

         /* Check for a function */
         template<class U> static
         yes_type detect(typename enable_if<is_same<U, Sig> >::type*);

         /* Check for a functor, either const and non-const members are
detected */
         template<ptm> struct helper;
         template<ptm_const> struct helper_const;

         template<class U> static
         yes_type detect(helper<&U::operator()>*);

         template<class U> static
         yes_type detect(helper_const<&U::operator()>*);

         /* Default */
         template<class U> static
         no_type detect(...);

         static const bool
         value = (sizeof(detect<F>(0)) == sizeof(yes_type));
     };


Where template pointer_to_member<> is:

    /* Convert a signature type Sig to a pointer_to_member type */
     template<int is_function, typename T, typename Sig>
     struct pointer_to_member;

     template<typename T, typename Sig>
     struct pointer_to_member<1, T, Sig> // filter out function types
     {
         typedef int type;
         typedef int const_type;
     };

     template<typename T, typename R>
     struct pointer_to_member<0, T, R()>
     {
         typedef R(T::* type) ();
         typedef R(T::* const_type)() const;
     };

     template<typename T, typename R, typename A0>
     struct pointer_to_member<0, T, R(A0)>
     {
         typedef R(T::* type)(A0);
         typedef R(T::* const_type)(A0) const;
     };

      ...... and so on for each argument arity ........


BTW it seems to work.


Thanks
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 Sat Jul 19 19:50:07 CDT 2008.