Namespaces
Variants
Views
Actions

std::result_of

From cppreference.com
< cpp‎ | types
Revision as of 15:03, 2 November 2012 by P12bot (Talk | contribs)

 
 
 
Type support
Basic types
Fundamental types
Fixed width integer types (C++11)
Numeric limits
C numeric limits interface
Runtime type information
Type traits
Primary type categories
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
Type properties
(C++11)
(C++11)
(C++11)
(C++14)
Supported operations
Relationships and property queries
(C++11)
(C++11)
(C++11)
(C++11)
Type modifications
(C++11)(C++11)(C++11)
Type transformations
(C++11)
(C++11)
result_of
(C++11)
Type trait constants
 

Template:ddcl list begin <tr class="t-dsc-header">

<td>
Defined in header <type_traits>
</td>

<td></td> <td></td> <tr class="t-dcl ">

<td >
template< class >
class result_of; //not defined
</td>

<td > (1) </td> <td > (since C++11) </td> </tr> <tr class="t-dcl ">

<td >
template< class F, class... ArgTypes >
class result_of<F(ArgTypes...)>;
</td>

<td > (2) </td> <td > (since C++11) </td> </tr> Template:ddcl list end

Deduces the return type of a function call expression at compile time.

Contents

Member types

Member type Definition
type the return type of the function F if called with the arguments ArgTypes...

Possible implementation

template<class>
struct result_of;
 
template<class F, class... ArgTypes>
struct result_of<F(ArgTypes...)>
{
    typedef decltype(
                     std::declval<F>()(std::declval<ArgTypes>()...)
                    ) type;
};

Example

struct S {
    double operator()(char, int&);
};
 
int main()
{
    std::result_of<S(char, int&)>::type f = 3.14; // f has type double
}


See also

(C++11)
obtains the type of expression in unevaluated context
(function template) [edit]