Categories: functors, adaptors | Component type: type |
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)));
Parameter | Description | Default |
---|---|---|
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. |
unary_function<AdaptableUnaryFunction1::argument_type, AdaptableBinaryFunction::result_type>
Member | Where defined | Description |
---|---|---|
argument_type | Adaptable Unary Function | The type of the function object's argument: AdaptableUnaryFunction::argument_type. |
result_type | Adaptable Unary Function | The type of the result: AdaptableBinaryFunction::result_type |
binary_compose(const AdaptableBinaryFunction& f, const AdaptableUnaryFunction1& g1, const AdaptableUnaryFunction1& g2); |
binary_compose | See below. |
template <class AdaptableBinaryFunction, class AdaptableUnaryFunction1, class AdaptableUnaryFunction2> binary_compose<AdaptableBinaryFunction, AdaptableUnaryFunction1, AdaptableUnaryFunction2> compose2(const AdaptableBinaryFunction&, const AdaptableUnaryFunction1&, const AdaptableUnaryFunction2&); |
binary_compose | See below. |
Member | Description |
---|---|
binary_compose(const AdaptableBinaryFunction& f, const AdaptableUnaryFunction1& g1, const AdaptableUnaryFunction1& g2); |
The constructor. Constructs a binary_compose object such that calling that object with the argument x returns f(g1(x), g2(x)). |
template <class AdaptableBinaryFunction, class AdaptableUnaryFunction1, class AdaptableUnaryFunction2> binary_compose<AdaptableBinaryFunction, AdaptableUnaryFunction1, AdaptableUnaryFunction2> compose2(const AdaptableBinaryFunction&, const AdaptableUnaryFunction1&, const AdaptableUnaryFunction2&); |
Creates a binary_compose object. If f, g, and g2 are, respectively, of classes AdaptableBinaryFunction, AdaptableUnaryFunction1, and AdaptableUnaryFunction2, then compose2(f, g1, g2) is equivalent to binary_compose<AdaptableBinaryFunction, AdaptableUnaryFunction1, AdaptableUnaryFunction2>(f, g1, g2), but is more convenient. This is a global function, not a member function. |
[1] This is a form of function composition. The unary_compose adaptor allows composition of Adaptable Unary Functions; note, however, that once binary functions are introduced, there are several possible patterns of function composition. The binary_compose allows you to form a unary function by putting together two unary functions and a binary function, but you could also, for example, imagine putting together two unary functions and a binary function to form a binary function. In that case, f, g1, and g2 would be combined into a function object h such that h(x,y) = f(g1(x), g2(y)).