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
fnof typeFnand valuest1, t2, ..., tNof typesT1, T2, ... TNinArgTypesrespectivly, thetypemember is the result type of the expressionfn(t1,t2,...,tN). the valuestiare lvalues when the corresponding typeTiis 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_ofinto a compiler-support trait was beyond the actual intention of the submitter Sebastian.
[
2010 Pittsburgh: Moved to NAD EditorialResolved, 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:typedefsee belowtype;};
Given an rvaluefnof typeFnand valuest1, t2, ..., tNof typesT1, T2, ... TNinArgTypesrespectivly, thetypemember is the result type of the expressionfn(t1,t2,...,tN). the valuestiare lvalues when the corresponding typeTiis an lvalue-reference type, and rvalues otherwise.The class template
result_ofshall meet the requirements of a TransformationTrait: Given the typesFn,T1,T2, ...,TNevery template specializationresult_of<Fn(T1,T2,...,TN)>shall define the member typedef type equivalent todecltype(RE)if and only if the expressionREvalue<Fn>() ( value<T1>(), value<T2>(), ... value<TN>() )would be well-formed. Otherwise, there shall be no member typedef
typedefined.
[
The value<> helper function is a utility Daniel Krügler
proposed in
N2958.
]