result_of Class
The latest version of this topic can be found at Visual Studio 2017 Documentation.
The return type of a wrapped callable object.
Syntax
struct result_of {
typedef T0 type;
};
Parameters
Ty
A description of a function call (see Remarks section).
Remarks
The template class defines its member type
as a synonym for the return type of a function call described by its template argument Ty
. The template argument must be of the form Fty(T1, T2, ..., TN)
, where Fty
is a callable type. The template determines the return type according to the first of the following rules that applies:
if
Fty
is a pointer to function typeR(*)(U1, U2, ..., UN)
the return type isR
;if
Fty
is a reference to function typeR(&)(U1, U2, ..., UN)
the return type isR
;if
Fty
is a pointer to member function typeR(U1::*)(U2, ..., UN)
the return type isR
;if
Fty
is a pointer to data member typeR U1::*
the return type isR
;if
Fty
is a class with a member typedefresult_type
the return type isFty::result_type
;if
N
is 0 (that is,Ty
is of the formFty()
) the return type isvoid
;if
Fty
is a class with a member template namedresult
the return type isFty::result<T1, T2, ..., TN>::type
;in all other cases it is an error.
Example
Â
// std_tr1__functional__result_of.cpp
// compile with: /EHsc
#include <functional>
#include <iostream>
double square(double x)
{
return (x * x);
}
template<class Fun,
class Arg>
void test_result(const Fun& fun, Arg arg)
{
typename std::result_of<Fun(Arg)>::type val = fun(arg);
std::cout << "val == " << val << std::endl;
}
int main()
{
test_result(&square, 3.0);
return (0);
}
val == 9
Requirements
Header: <functional>
Namespace: std