Boost logo

Boost :

Subject: Re: [boost] [result_of] Allow result_of to work with C++11 lambdas
From: Jeffrey Lee Hellrung, Jr. (jeffrey.hellrung_at_[hidden])
Date: 2013-04-21 21:53:32


On Sun, Apr 21, 2013 at 6:35 PM, Peter Dimov <lists_at_[hidden]> wrote:

> Jeffrey Lee Hellrung, Jr. wrote:
>
>> On Sun, Apr 21, 2013 at 7:48 AM, Daniel Walker <daniel.j.walker_at_[hidden]
>> >**wrote:
>> > This is due to a dark corner of TR1: the result and result_type members
>> > are consulted in non-nullary functors but nullary functors always >
>> generate
>> > void. (See the section on known difference between boost::result_of and
>> > TR1
>> > in the documentation.)
>>
>> The rationale for this always confused me, with the end result (it seems)
>> that it makes TR1 result_of basically unusable for nullary function calls.
>>
>
> result_type is consulted. result<> is not. type is void (instead of a
> compile error) when there is no result_type.
>
> The reason for the type being void is that in
>
> template<class T> class reference_wrapper
> {
> private:
>
> T & t_;
>
> public:
>
> typename result_of<T()>::type operator()() const
> {
> return t_();
> }
> };
>
> operator()() is not a template. If result_of<T()>::type wasn't present or
> generated an error when T doesn't have result<>, reference_wrapper<int>
> would have generated an error when instantiated.
>
> In C++11, you can make operator()() a template. In C++03, you can't.
>

Oh. Right.

I believe this can be worked around by conditionally defining operator()()
(by conditionally inheriting from various base classes) only if T has
operator()(), but that's a more complex solution.

- Jeff


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