Boost logo

Boost Users :

Subject: Re: [Boost-users] [range] cannot use lambda predicate in adaptor with certain algorithms
From: Daniel Walker (daniel.j.walker_at_[hidden])
Date: 2011-05-30 15:46:41

On Mon, May 30, 2011 at 12:41 PM, Michel MORIN <mimomorin_at_[hidden]> wrote:
> Akira Takahashi wrote:
>> C++0x lambda hasn't result_type typedef
> Ah, this is the reason for the compiler error. Thanks for correcting me.
> (Cc'ing to Daniel)
> So, when using boost::result_of with C++0x lambda functions,
> we have to define BOOST_RESULT_OF_USE_DECLTYPE.
> This is a bit bothersome, and so I expect that, in the future,
> BOOST_RESULT_OF_USE_DECLTYPE gets automatically defined
> in compilers with N3276 support.
> Something like
> // boost/utility/result_of.hpp
> #ifndef #BOOST_NO_DECLTYPE_N3276
> #endif
> ?
> (BOOST_NO_DECLTYPE_N3276 is not yet included in Boost.Config.)

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;
   static_assert(is_same<type, double>::value, "");
   static_assert(is_same<type, int>::value, "");

Also, I'm sure a config macro will be added for N3276, though I'm not
sure what its exact name will be. For example, current decltype
implementations work in context where the result type is complete.
N3276 requires them to also work in context where the result type is
incomplete. So, a more descriptive name might be

Daniel Walker

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at