Why don't lambda funcs work for stl function objects?

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.

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. Jaakko

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> > { };
participants (3)
-
Jaakko Jarvi
-
Justinas V.D.
-
Neal D. Becker