ptr_fun function template — Creates a pointer to a function object
template <typename Arg1, typename Arg2, typename Rtn> pointer_to_binary_function<Arg1,Arg2,Rtn> ptr_fun(Rtn (*f)(Arg1, Arg2)); template <typename Arg, typename Rtn> pointer_to_unary_function<Arg, Rtn> ptr_fun(Rtn (*f)(Arg));
The ptr_fun
function
template creates a function object from a pointer to a function. The
resulting function object has an operator(
)
that calls the function. Functions of one and two
arguments are supported.
For example, suppose you have two numeric vectors, a
and b
, and you want to raise each element of
a
to the power of the
corresponding element in b
,
saving the result in a third vector, c
. There is no predefined power function
object, so you can use ptr_fun
and your own power
function
instead, as shown in Example
13-13.