This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of Resolved status.

### 1225. C++0x `result_of` issue

Section: 99 [func.ret] Status: Resolved Submitter: Sebastian Gesemann Opened: 2009-10-05 Last modified: 2016-01-28

Priority: Not Prioritized

View all other issues in [func.ret].

View all issues with Resolved status.

Discussion:

I think the text about `std::result_of` could be a little more precise. Quoting from N2960...

> 99 [func.ret] Function object return types

>     template<class> class result_of;

>     template<class Fn, class... ArgTypes>
>     class result_of<Fn(ArgTypes...)> {
>     public:
>       typedef see below type;
>     };

> Given an rvalue `fn` of type `Fn` and values `t1, t2, ..., tN` of types `T1, T2, ... TN` in `ArgTypes` respectivly, the `type` member is the result type of the expression `fn(t1,t2,...,tN)`. the values `ti` are lvalues when the corresponding type `Ti` is an lvalue-reference type, and rvalues otherwise.

This text doesn't seem to consider lvalue reference types for `Fn`. Also, it's not clear whether this class template can be used for "SFINAE" like `std::enable_if`. Example:

>     template<typename Fn, typename... Args>
>     typename std::result_of<Fn(Args...)>::type
>     apply(Fn && fn, Args && ...args)
>     {
>       // Fn may be an lvalue reference, too
>       return std::forward<Fn>(fn)(std::forward<Args>(args)...);
>     }

Either `std::result_of<...>` can be instantiated and simply may not have a typedef "`type`" (-->SFINAE) or instantiating the class template for some type combinations will be a "hard" compile-time error.

[ 2010-02-14 Daniel adds: ]

> This issue should be considered resolved by 1255 and 1270. The wish to change `result_of` into a compiler-support trait was beyond the actual intention of the submitter Sebastian.

[ 2010 Pittsburgh: Moved to NAD Editorial Resolved, rationale added below. ]

Rationale:

Solved by 1270.

Proposed resolution:

[ These changes will require compiler support ]

Change 99 [func.ret]:

>     template<class> class result_of; // undefined

>     template<class Fn, class... ArgTypes>
>     class result_of<Fn(ArgTypes...)> {
>     public:
>       typedef see below type;
>     };

> Given an rvalue `fn` of type `Fn` and values `t1, t2, ..., tN` of types `T1, T2, ... TN` in `ArgTypes` respectivly, the `type` member is the result type of the expression `fn(t1,t2,...,tN)`. the values `ti` are lvalues when the corresponding type `Ti` is an lvalue-reference type, and rvalues otherwise.

> The class template `result_of` shall meet the requirements of a TransformationTrait: Given the types `Fn`, `T1`, `T2`, ..., `TN` every template specialization `result_of<Fn(T1,T2,...,TN)>` shall define the member typedef type equivalent to `decltype(RE)` if and only if the expression `RE`

> >     value<Fn>() ( value<T1>(), value<T2>(), ... value<TN>()  )

> would be well-formed. Otherwise, there shall be no member typedef `type` defined.

[ The `value<>` helper function is a utility Daniel Krügler proposed in N2958. ]