...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
template <class F> struct function_traits { static const std::size_t arity =see-below
; typedefsee-below
result_type; typedefsee-below
argN
_type; };
The class template function_traits will only compile if:
F
is a function type, note that this is not the same thing as a pointer
to a function.
Tip | |
---|---|
function_traits is intended to introspect only C++ functions of the form R (), R( A1 ), R ( A1, ... etc. ) and not function pointers or class member functions. To convert a function pointer type to a suitable type use remove_pointer. |
Table 1.20. Function Traits Members
Member |
Description |
---|---|
|
An integral constant expression that gives the number of arguments
accepted by the function type |
|
The type returned by function type |
|
The |
Table 1.21. Examples
Expression |
Result |
---|---|
|
An integral constant expression that has the value 0. |
|
An integral constant expression that has the value 1. |
|
An integral constant expression that has the value 4. |
|
The type |
|
The type |
|
The type |
|
The type |
|
A compiler error: there is no |
|
A compiler error: argument type is a function pointer, and not a function type. |
Compiler Compatibility: All current compilers are supported by this trait.