Title
C++0x result_of issue
Status
resolved
Section
[func.ret]
Submitter
Sebastian Gesemann

Created on 2009-10-05.00:00:00 last changed 170 months ago

Messages

Date: 2010-10-21.18:28:33

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

Date: 2010-10-21.18:28:33

[ These changes will require compiler support ]

Change [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.

Date: 2010-10-21.18:28:33

Rationale:

Solved by 1270.

Date: 2010-12-05.00:09:22

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

Date: 2010-02-14.00:00:00

[ 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.

Date: 2009-10-05.00:00:00

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

[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.

History
Date User Action Args
2010-12-05 00:09:22adminsetstatus: nad editorial -> resolved
2010-10-21 18:28:33adminsetmessages: + msg1219
2010-10-21 18:28:33adminsetmessages: + msg1218
2010-10-21 18:28:33adminsetmessages: + msg1217
2010-10-21 18:28:33adminsetmessages: + msg1216
2010-10-21 18:28:33adminsetmessages: + msg1215
2009-10-05 00:00:00admincreate