Unary_compose is a function object adaptor. If f and g are both
Adaptable Unary Functions, and if g's return type is convertible
to f's argument type, then unary_compose can be used to create a
function object h such that h(x) is the same as f(g(x)). [1] As
with other function object adaptors, the easiest way to create a
unary_compose is to use the helper function compose1. It is
possible to call unary_compose's constructor directly, but there
is usually no reason to do so.
Example
Calculates the negative of the sines of the elements in a vector, where the elements
are angles measured in degrees. Since the C library function sin
takes its arguments in radians, this operation is the composition of
three operations: negation, sin, and the conversion of degrees to radians.
Defined in the standard header functional, and in the nonstandard
backward-compatibility header function.h. The unary_compose
class is an SGI extension; it is not part of the C++ standard.
Template parameters
Parameter
Description
Default
AdaptableUnaryFunction1
The type of the first operand in the function composition operation.
That is, if the composition is written f o g[1], then
AdaptableUnaryFunction1 is the type of the function object f.
AdaptableUnaryFunction2
The type of the second operand in the function composition operation.
That is, if the composition is written f o g[1], then
AdaptableUnaryFunction1 is the type of the function object g.
AdaptableUnaryFunction1 and AdaptableUnaryFunction2 must both
be models of Adaptable Unary Function.
AdaptableUnaryFunction2::result_type must be convertible to
AdaptableUnaryFunction1::argument_type.
Creates a unary_compose object. If f and g are, respectively, of classes
AdaptableUnaryFunction1 and AdaptableUnaryFunction2, then
compose1(f, g) is equivalent to
unary_compose<AdaptableUnaryFunction1, AdaptableUnaryFunction2>(f, g),
but is more convenient. This is a global function, not a member function.
Notes
[1]
This operation is called function composition, hence
the name unary_compose. It is often represented in mathematics
as the operation f o g, where f o g is a function such that
(f o g)(x) == f(g(x)). Function composition is a very important
concept in algebra. It is also extremely important as a method
of building software components out of other components, because
it makes it possible to construct arbitrarily complicated function
objects out of simple ones.