Boost logo

Boost Users :

From: Tobias Schwinger (tschwinger_at_[hidden])
Date: 2006-08-12 17:21:33


Peter Soetens wrote:
> Hi,
>
> I was looking for a way to convert a member function type:
>
> bool (X::*)(int) or bool (X::)(int)
>
> to the 'C' equivalent, without the class pointer:
>
> bool (*)(int) or bool(int)
>

[code]

>
> Is there an easier way to do this ?
>

Yes.

If your compiler behaves you can use template partial specialization for a
member pointer to do this transformation.
Unfortunately, it's not very portable, currently. It's the reason to use
FunctionTypes here in the first place.

Using the upcoming version (preview in the vault http://tinyurl.com/qpffx)
of FunctionTypes your "unmember" template would look like this:

   template<typename F>
   struct unmember
     : function_pointer
       < mpl::joint_view< mpl::single_view< typename result_type<F>::type >
                        , typename mpl::pop_front< parameter_types<F> >::type
> >
   { };

Things are a little different with the older version you appear to be using:
a) omit mpl::pop_front (parameter_types<F> includes the class type, now)
b) use typename function_type_parameters<F>::type (note: typename...type
  is needed, because function_type_parameters<F> does not model an MPL
  sequence, only its type member does)

BTW: Not removing the class type (creating a function that takes the class
context in form of a properly cv-qualified reference) is even simpler:

   function_pointer<F>::type
   // is 'bool (*)(X &,int)' for F = 'bool (X::*)(int)'
   // is 'bool (*)(X const &,int)' for F = 'bool (X::*)(int) const'

To encourage you to use the new version and because the documentation is
still not finished, I just uploaded the source code examples:

   http://tinyurl.com/mkjv7

Regards,

Tobias


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net