Boost logo

Boost Users :

Subject: Re: [Boost-users] [range] cannot use lambda predicate in adaptor with certain algorithms
From: Michel MORIN (mimomorin_at_[hidden])
Date: 2011-05-31 21:37:17


Hi Daniel,

Daniel Walker wrote:
> At some point, BOOST_RESULT_OF_USE_DECLTYPE may be defined by default,
> probably when there's enough user interest, so thanks for cc'ing me.
> The reason it is currently not defined by default is that it is
> possible that it could introduce breaking changes to some C++03
> function objects; e.g. if a function object defines result_type to be
> some type other than the type of a call expression, then in C++03
> result_of would give the user-specified result_type rather than the
> actual result type, whereas in C++0x result_of always gives the actual
> result type. For example:
>
> #include <boost/type_traits.hpp>
> #include <boost/utility/result_of.hpp>
>
> struct f {
>    typedef int result_type;
>    double operator()(double);
> };
>
> int main()
> {
>    using namespace boost;
>    typedef result_of<f(double)>::type type;
> #ifdef BOOST_RESULT_OF_USE_DECLTYPE
>    static_assert(is_same<type, double>::value, "");
> #else
>    static_assert(is_same<type, int>::value, "");
> #endif
> }

Thank you for explaining the problem.
And yes, backward compatibility is always problematic.

IMO, this use case is not the intended use of boost::result_of,
so is it reasonable to deprecate this?
And how about adding a "Note" that warns this kind of codes will break
in the future to the documentation?

Regards,
Michel

P.S. Eric just completed a patch for BOOST_NO_DECLTYPE_N3276:
http://permalink.gmane.org/gmane.comp.lib.boost.devel/219979


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