Subject: Re: [boost] [utility][thread] result_of - erroneous result type from a C++11 lambda
From: Daniel Walker (daniel.j.walker_at_[hidden])
Date: 2013-06-17 15:07:07
On Jun 17, 2013, at 2:27 PM, Klaim - Joël Lamotte <mjklaim_at_[hidden]> wrote:
> On Mon, Jun 17, 2013 at 8:06 PM, Daniel Walker <daniel.j.walker_at_[hidden]>wrote:
>> If I'm not mistaken, it looks like you are using the TR1 protocol with
>> nullary functions. See the bullet point on nullary functions in the
>> TR1 cannot deduce the return type of nullary function objects. You
>> probably either want to use std::result_of or boost::result_of with
>> BOOST_RESULT_OF_USE_DECLTYPE defined. If you really must use TR1 there are
>> workarounds for the nullary function issue discussed at the same bullet
>> point at the link above, but these workarounds may not be applicable in
>> your situation. In C++11, I would not recommend using TR1 unless you need
>> it for backwards compatibility/portability to C++03, in which case you
>> can't deduce return types for nullary function objects.
> In my own VS2012 code I use decltype exclusively.
> But that do not fix the problem for boost libraries themselves:
> Boost.Thread (future, async) apparently uses boost::result_of which makes
> the two first example I provide go wrong and
> makes both async and .then unusable.
> My understanding was that indeed these libraries would automatically use
> decltype() in the implementation if available, not tr1::result_of or
> something else.
> Is automatically BOOST_RESULT_OF_USE_DECLTYPE defined for VS2012? If not
> isn't it a bug? decltype is available whatever the compilation flags you
BOOST_RESULT_OF_USE_DECLTYPE is automatically defined when BOOST_NO_CXX11_DECLTYPE_N3276 is not defined; i.e. it's only enabled by default when the compiler has fairly complete decltype support including N3276. As of Boost 1.53.0, it appears this is not the case for any version of Visual Studio. (See boost/config/compiler/visualc.hpp starting at line 224 for unsupported features.) I don't know if there's been any progress on that front from Microsoft, but as soon as N3276 is enabled in Boost's compiler config file, result_of will use decltype by default for that compiler.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk