Boost logo

Boost :

From: João Abecasis (jpabecasis_at_[hidden])
Date: 2006-05-30 19:41:48


Tobias Schwinger wrote:
> Tobias Schwinger wrote:
>> João Abecasis wrote:
>>
>>> 1 - support for function pointers was completely broken.
>>> Specifically, I learned that result_of doesn't handle cv-qualified
>>> function pointers.
>>
>>
>> <snip>
>>
>>
>>> 3 - Function references weren't handled at all.
>>
>>
>> Taking the function argument by value (just like the STL) could help.
> ...which might be why result_of doesn't address the cases you describe.

Yes, I thought that would be the reason why this wasn't noticed before.
Anyway, the code that's needed to allow for situations like these is
minimal, so it was not too much trouble once I understood the issues:

     typedef mpl::eval_if<
         is_pointer<F>,
         remove_cv<F>,
         mpl::eval_if<
             is_function<remove_cv<F>::type>,
             add_pointer<remove_cv<F>::type>,
             mpl::identity<F>
>
>::type F_;

     typedef result_of<F_( args )>::type result_type;

> We can still optimize the forwarding from unpack_args to
> unpack_args_impl and the client can optimize the forwarding to
> unpack_args by explicitly
> specifying the first template argument (see attached code).

The problem I had was that I needed a type for result_of (e.g.,
non-cv-qualified function pointer) and another type to pass around
(e.g., function reference). By themselves, references work pretty well.

Best regards,

João


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk