|
Boost Users : |
From: Peter Soetens (peter.soetens_at_[hidden])
Date: 2006-08-16 04:45:50
On Saturday 12 August 2006 23:21, Tobias Schwinger wrote:
> 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
>
> { };
Thanks for this update, I really appreciate the work you are putting in this
library, and it effectively helps me to solve 'delegate-like' problems in my
application framework.
>
> 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)
I'm distributing the function_types headers with my library (until it gets
into boost), so I can include a new version if needed so.
>
>
> 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'
>
Thanks, but I wanted the X& to be a pointer as well. OTOH, maybe I can change
my code to pass a reference to X.
>
> 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
Examples are of great help to grasp the possibilities or syntax of this
library.
Peter
-- Peter Soetens -- FMTC -- <http://www.fmtc.be>
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