result_of Class
The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.
The latest version of this topic can be found at Visual Studio 2017 Documentation. The return type of a wrapped callable object.
struct result_of {
typedef T0 type;
};
Parameters
Ty
A description of a function call (see Remarks section).
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
Ftyis a pointer to function typeR(*)(U1, U2, ..., UN)the return type isR;if
Ftyis a reference to function typeR(&)(U1, U2, ..., UN)the return type isR;if
Ftyis a pointer to member function typeR(U1::*)(U2, ..., UN)the return type isR;if
Ftyis a pointer to data member typeR U1::*the return type isR;if
Ftyis a class with a member typedefresult_typethe return type isFty::result_type;if
Nis 0 (that is,Tyis of the formFty()) the return type isvoid;if
Ftyis a class with a member template namedresultthe return type isFty::result<T1, T2, ..., TN>::type;in all other cases it is an error.
Â
// 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
Header: <functional>
Namespace: std