|
Boost Users : |
From: Tobias Schwinger (tschwinger_at_[hidden])
Date: 2006-08-25 16:25:11
Peter Soetens wrote:
> On Friday 18 August 2006 08:34, Tobias Schwinger wrote:
>
>>Peter Soetens wrote:
>>
>>>On Saturday 12 August 2006 23:21, Tobias Schwinger wrote:
>>>>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'
>>
>
> This is a complete killer-template. You are a genious.
Thanks. It's MPL that makes it possible, so I have to pass some of the fame
to Aleksey. The review brought up the points that led to the current design
so another portion goes to the reviewers...
> If this becomes the 'look-and-feel' interface of the whole library
> (instead of the 'tags'), it will be an example for many other meta
> programming libraries.
Well there are still tags, but in many cases you don't have to care about
them. Further there are only "atomary" tags, that is they can be combined
by the user. Here are some example use cases:
function_pointer<mpl::vector<int,int>,stdcall_cc>::type
// is int(__stdcall*)(int)
is_function<typeof(printf),variadic>::value // == true
is_function<typeof(memcpy),variadic>::value // == false
member_function_pointer<type_sequence,non_const>::type
// never const, regardless of the class type in the sequence
member_function_pointer<type_sequence,tag<non_const,non_volatile> >::type
// never cv, regardless of the class type in the sequence
Not using tag types for situations like these ones would either
a) require to strip down the functionality of the library, or
b) lead to countless templates for different combinations (pretty
much just as bad as having that many tags around).
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