Boost logo

Boost :

From: Jaakko Jarvi (jajarvi_at_[hidden])
Date: 2004-02-24 14:41:06


Hi Peter,

I think the change is good.
There's currently the 'std_functor' wrapper that instructs BLL to look for
result_type instead of sig, but since we do have has_xxx...

Drop me a note once you've done it, I'll update the docs.

  Jaakko

On Tue, 24 Feb 2004, Peter Dimov wrote:

> The following patch to boost/lambda/detail/return_type_traits.hpp enables it
> to extract the return type information from a nested ::result_type typedef
> instead of insisting on a sig<> template. This is useful since all standard
> function objects in <functional> and many user-defined function objects
> (including those produced by boost::mem_fn) have result_type but no sig<>.
>
> I have not commited the patch yet, even though it seems to work fine for me,
> since it alters the Lambda behavior in the case where a function object
> defines both result_type and sig<>. Currently, sig<> is used. With the
> patch, result_type would override sig<>.
>
> All function objects known to man that have both do define sig<> to return
> the same type as result_type; nevertheless, I'd like confirmation from the
> maintainers first, before I commit.
>
> Thanks for listening; patch follows:
>
> *** 17,22 ****
> --- 17,24 ----
> #ifndef BOOST_LAMBDA_RETURN_TYPE_TRAITS_HPP
> #define BOOST_LAMBDA_RETURN_TYPE_TRAITS_HPP
>
> + #include "boost/mpl/aux_/has_xxx.hpp"
> +
> #include <cstddef> // needed for the ptrdiff_t
>
> namespace boost {
> ***************
> *** 239,244 ****
> --- 241,265 ----
> typedef Ret type;
> };
>
> + // ::result_type support
> +
> + namespace detail
> + {
> +
> + BOOST_MPL_HAS_XXX_TRAIT_DEF(result_type)
> +
> + template<class F> struct get_result_type
> + {
> + typedef typename F::result_type type;
> + };
> +
> + template<class F, class A> struct get_sig
> + {
> + typedef typename function_adaptor<F>::template sig<A>::type type;
> + };
> +
> + } // namespace detail
> +
> // Ret is detail::unspecified, so try to deduce return type
> template<int I, class Args>
> struct return_type_N<function_action<I, detail::unspecified>, Args > {
> ***************
> *** 251,257 ****
> public:
> // pass the function to function_adaptor, and get the return type from
> // that
> ! typedef typename function_adaptor<plain_Func>::template sig<Args>::type
> type;
> };
>
>
> --- 272,282 ----
> public:
> // pass the function to function_adaptor, and get the return type from
> // that
> ! typedef typename detail::IF<
> ! detail::has_result_type<plain_Func>::value,
> ! detail::get_result_type<plain_Func>,
> ! detail::get_sig<plain_Func, Args>
> ! >::RET::type type;
> };
>
> --
> Peter Dimov
> http://www.pdimov.com
>
> _______________________________________________
> Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
>


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