|
Boost Users : |
From: Tobias Schwinger (tschwinger_at_[hidden])
Date: 2006-08-18 02:34:09
Peter Soetens wrote:
> 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.
I'm glad to hear that!
>>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.
>
function_pointer<F>::type
is a shortcut for
function_pointer< components<F> >::type
and 'components' has a second template parameter, an MPL Lambda Expression,
that allows to change the way the class type is transformed (and so has
'parameter_types'):
function_pointer< components< F, add_pointer<_> >::type
// is 'bool (*)(X *,int)' for F = 'bool (X::*)(int)'
// is 'bool (*)(X const *,int)' for F = 'bool (X::*)(int) const'
function_pointer< components< F, add_pointer< remove_cv<_> > >::type
// is 'bool (*)(X *,int)' for F = 'bool (X::*)(int)'
// is 'bool (*)(X *,int)' for F = 'bool (X::*)(int) const'
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