Copyright (C) 2000-2012 |
Whole document tree unary_compose<AdaptableUnaryFunction1,AdaptableUnaryFunction2>
DescriptionUnary_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.ExampleCalculates 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.vector<double> angles; vector<double> sines; const double pi = 3.14159265358979323846; ... assert(sines.size() >= angles.size()); transform(angles.begin(), angles.end(), sines.begin(), compose1(negate<double>(), compose1(ptr_fun(sin), bind2nd(multiplies<double>(), pi / 180.)))); DefinitionDefined 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
Model ofAdaptable Unary FunctionType requirementsAdaptableUnaryFunction1 and AdaptableUnaryFunction2 must both be models of Adaptable Unary Function. AdaptableUnaryFunction2::result_type must be convertible to AdaptableUnaryFunction1::argument_type.Public base classesunary_function<AdaptableUnaryFunction2::argument_type, AdaptableUnaryFunction1::result_type> Members
New membersThese members are not defined in the Adaptable Unary Function requirements, but are specific to unary_compose.
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. See alsoThe function object overview, binary_compose, binder1st, binder2nd.Copyright © 1999 Silicon Graphics, Inc. All Rights Reserved. TrademarkInformation
|