Fixing the Problem
The function wrapper lets you rewrite the program so that it uses just one instantiation of use_f()
instead of five. Note that the function pointers, function objects, and lambda expressions in Listing 18.7 share a common behavior—each takes one type double
argument and each returns a type double
value. We can say that each has the same call signature, which is described by the return type followed by a comma-separated list of parameter types enclosed in a pair of parentheses. Thus, these six examples all have double(double)
as the call signature.
The function
template, declared in the functional
header file, specifies an object in terms of a call signature, and it can be used to wrap a function pointer, function object, or ...
Get C++ Primer Plus now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.