Boost logo

Boost :

From: Justinas V.D. (vygintas.daugmaudis_at_[hidden])
Date: 2004-05-13 16:53:17


Jaakko Jarvi wrote:
>
> On May 13, 2004, at 3:32 PM, Neal D. Becker wrote:
>
>> Any reason lambda functions can't meet requirements for
>> std::unary_function,
>> for example? Specifically, it seems result_type is not defined.
>>
>> For example boost::constant(0) doesn't have result_type, so can't be used
>> where a std::unary_function is needed.
>>
>
> In general the result_type is not known until the parameter types of the
> lambda_functor
> are known. So for consistency (or laziness), result_type is not provided
> for any
> lambda functor.

It's quite trivial to fix this though. When I was in somewhat analogical
situation, I just wrote 2 simple metafunctions. Mayhap that can help
someone. Note that result_of template is used (in CVS now).

         // Just for unary lambdas and unary functors
         template<typename ExprT, typename ParamT>
         struct result_of_unary_lambda :
             ExprT::template sig<tuple<ExprT, ParamT> >
         {
         };

         template<typename ExprT, typename ParamT>
         struct result_of_unary : mpl::apply_if<
             mpl::bool_<lambda::is_lambda_functor<ExprT>::value>
           , result_of_unary_lambda<ExprT, ParamT>
           , result_of<ExprT, ParamT>
>
         {
         };


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