Boost logo

Boost Users :

Subject: Re: [Boost-users] [Range & c++0x Lambdas] Can this be done?
From: Eric Niebler (eric_at_[hidden])
Date: 2012-11-21 16:26:21


On 11/21/2012 11:27 AM, Nathan Ridge wrote:
>
>> On Wed, Nov 21, 2012 at 5:15 PM, Nathan Crookston
>> <nathan.crookston_at_[hidden]<mailto:nathan.crookston_at_[hidden]>> wrote:
>> Rob,
>>
>> On Wed, Nov 21, 2012 at 6:39 AM, Robert Jones
>> <robertgbjones_at_[hidden]<mailto:robertgbjones_at_[hidden]>> wrote:
>> Can the last line, labelled NOT Ok, be made to work? I think the lambda does
>> not publish its result as a bind does, so I suspect it's hopeless. Any
>> thoughts?
>> // NOT Ok
>> boost::range::push_back( out, in | transformed( []( S & s ) {
>> return s.i; } ) );
>> }
>>
>> It seems trivial to have a nested result_type in all cases with a
>> lambda. However, in C++11 there's no need for it due to decltype.
>>
>> Sadly, some compilers fall into a gap where result_of (boost or std)
>> doesn't use decltype and lambdas don't publish tr1-style result_type --
>> leaving code like the above in the lurch.
>>
>> Michel Morin wrote some code for adapting such a case which may be of
>> interest to you: http://lists.boost.org/boost-users/2012/01/72879.php
>>
>> Right, thank you for that informative explanation. So, several
>> solutions, non perfect. Choose
>> your poison!
>>
>> - Rob.
>
> I've been turning on BOOST_RESULT_OF_USE_DECLTYPE for such occasions
> and haven't had any problems with it.

It's *mostly* safe on *most* modern compilers to do that. Boost has been
very cautious about rolling out its decltype-based result_of
implementation because "mostly" doesn't cut it. But starting with 1.52,
it's enabled by default on clang 3.1 and higher. More compilers will be
added as their decltype support improves.

-- 
Eric Niebler
BoostPro Computing
http://www.boostpro.com

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