unary_compose, binary_compose

unary_compose<AdaptableUnaryFunction1,AdaptableUnaryFunction2>

Categories: functors, adaptors

Component type: type

Description

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.

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.))));

Definition

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
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.
Model of

Adaptable Unary Function

Type requirements

AdaptableUnaryFunction1 and AdaptableUnaryFunction2 must both be models of Adaptable Unary Function. AdaptableUnaryFunction2::result_type must be convertible to AdaptableUnaryFunction1::argument_type.

Public base classes

unary_function<AdaptableUnaryFunction2::argument_type, AdaptableUnaryFunction1::result_type>

Members
Member Where defined Description
argument_type Adaptable Unary Function The type of the function object's argument: AdaptableUnaryFunction2::argument_type.
result_type Adaptable Unary Function The type of the result: AdaptableUnaryFunction1::result_type
unary_compose(const AdaptableUnaryFunction1& f, const AdaptableUnaryFunction2& g); unary_compose See below.
template <class AdaptableUnaryFunction1, class AdaptableUnaryFunction2> unary_compose<AdaptableUnaryFunction1, AdaptableUnaryFunction2> compose1(const AdaptableUnaryFunction1& op1, const AdaptableUnaryFunction2& op2); unary_compose See below.
New members

These members are not defined in the Adaptable Unary Function requirements, but are specific to unary_compose.

Добавить отзыв
ВСЕ ОТЗЫВЫ О КНИГЕ В ИЗБРАННОЕ

0

Вы можете отметить интересные вам фрагменты текста, которые будут доступны по уникальной ссылке в адресной строке браузера.

Отметить Добавить цитату