Member | Description |
unary_compose(const AdaptableUnaryFunction1& f, const AdaptableUnaryFunction2& g); | The constructor. Constructs a unary_compose object that represents the function object f o g. [1] |
template <class AdaptableUnaryFunction1, class AdaptableUnaryFunction2> unary_compose<AdaptableUnaryFunction1, AdaptableUnaryFunction2> compose1(const AdaptableUnaryFunction1& op1, const AdaptableUnaryFunction2& op2); | 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.
See also The function object overview, binary_compose, binder1st, binder2nd.
binary_compose<AdaptableBinaryFunction,AdaptableUnaryFunction1,AdaptableUnaryFunction2>
Categories: functors, adaptors
Component type: type
Description Binary_compose is a function object adaptor. If f is an Adaptable Binary Function and g1 and g2 are both Adaptable Unary Functions, and if g1's and g2's return types are convertible to f's argument types, then binary_compose can be used to create a function object h such that h(x) is the same as f(g1(x), g2(x)). [1] [2]
Example Finds the first element in a list that lies in the range from 1 to 10.
list<int> L;
…
list<int>::iterator in_range = find_if(L.begin(), L.end(), compose2(logical_and<bool>(), bind2nd(greater_equal<int>(), 1), bind2nd(less_equal<int>(), 10)));
assert(in_range == L.end() || (*in_range >= 1 && *in_range <= 10));
Computes sin(x)/(x + DBL_MIN) for each element of a range.
transform(first, last, first, compose2(divides<double>(), ptr_fun(sin), bind2nd (plus<double>(), DBL_MIN)));
Definition Defined in the standard header functional, and in the nonstandard backward-compatibility header function.h. The binary_compose class is an SGI extension; it is not part of the C++ standard.
Template parameters Parameter | Description |
AdaptableBinaryFunction | The type of the 'outer' function in the function composition operation. That is, if the binary_compose is a function object h such that h (x) = f(g1(x), g2(x)), then AdaptableBinaryFunction is the type of f. |
AdaptableUnaryFunction1 | The type of the first 'inner' function in the function composition operation. That is, if the binary_compose is a function object h such that h (x) = f(g1(x), g2(x)), then AdaptableBinaryFunction is the type of g1. |
AdaptableUnaryFunction2 | The type of the second 'inner' function in the function composition operation. That is, if the binary_compose is a function object h such that h (x) = f(g1(x), g2(x)), then AdaptableBinaryFunction is the type of g2. |
Model of Adaptable Unary Function
Type requirements AdaptableBinaryFunction must be a model of Adaptable Binary Function. AdaptableUnaryFunction1 and AdaptableUnaryFunction2 must both be models of Adaptable Unary Function. The argument types of AdaptableUnaryFunction1 and AdaptableUnaryFunction2 must be convertible to each other. The result types of AdaptableUnaryFunction1 and AdaptableUnaryFunction2 must be convertible, respectively, to the first and second argument types of AdaptableBinaryFunction.
Public base classes unary_function<AdaptableUnaryFunction1::argument_type,