class template
<type_traits>

std::result_of

template <class Fn, class... ArgTypes> struct result_of<Fn(ArgTypes...)>;
Result of call
Obtains the result type of a call to Fn with arguments of the types listed in ArgTypes.

The result type is aliased as member type result_of::type, which is defined in any of the following cases:

  • If Fn is a function or a function object type that takes ArgTypes as arguments.
  • If Fn is a pointer to a non-static member function, and the first type in ArgTypes is the class the member belongs to (or a reference to it, or a reference to a derived type, or a pointer to it), and the remaining types in ArgTypes describe its arguments.
  • If Fn is a pointer to a non-static data member, and ArgTypes is a single type that matches the class the member belongs to (or a reference to it, or a reference to a derived type, or a pointer to it). In this case, member type is the type of this data member.
In all other cases, member type is not defined.

Template parameters

Fn
A callable type (i.e., a function object type or a pointer to member), or a reference to a function, or a reference to a callable type.
ArgTypes...
A list of types, in the same order as in the call.
Notice that the template parameters are not comma-separated, but in functional form.

Member types

member typedefinition
typeThe result type of a call to Fn with arguments of the types specified in ArgTypes.

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
// result_of example
#include <iostream>
#include <type_traits>

int fn(int) {return int();}                            // function
typedef int(&fn_ref)(int);                             // function reference
typedef int(*fn_ptr)(int);                             // function pointer
struct fn_class { int operator()(int i){return i;} };  // function-like class

int main() {
  typedef std::result_of<decltype(fn)&(int)>::type A;  // int
  typedef std::result_of<fn_ref(int)>::type B;         // int
  typedef std::result_of<fn_ptr(int)>::type C;         // int
  typedef std::result_of<fn_class(int)>::type D;       // int

  std::cout << std::boolalpha;
  std::cout << "typedefs of int:" << std::endl;

  std::cout << "A: " << std::is_same<int,A>::value << std::endl;
  std::cout << "B: " << std::is_same<int,B>::value << std::endl;
  std::cout << "C: " << std::is_same<int,C>::value << std::endl;
  std::cout << "D: " << std::is_same<int,D>::value << std::endl;

  return 0;
}


Output:
typedefs of int:
A: true
B: true
C: true
D: true

See also

<type_traits>