requirements. Identity does not introduce any new members.

Notes

[1] It is essential that the return type and the argument type are the same: generalizing identity to allow them to differ would not work. The reason is that identity returns a const reference to its argument, rather than a copy of its argument. If identity were allowed to perform a conversion, then this would be a dangling reference.

See also

The function object overview, select1st, select2nd, project1st, project2nd

project1st<Arg1, Arg2>

Category: functors

Component type: type

Description

Project1st is a function object that takes two arguments and returns its first argument; the second argument is unused. It is essentially a generalization of identity to the case of a Binary Function.

Example

int main() {

 vector<int> v1(10, 137);

 vector<char*> v2(10, (char*) 0);

 vector<int> result(10);

 transform(v1.begin(), v1.end(), v2.begin(), result.begin(), project1st<int, char*> ());

 assert(equal(v1.begin(), v1.end(), result.begin()));

}

Definition

Defined in the standard header functional, and in the nonstandard backward-compatibility header function.h. This function object is an SGI extension; it is not part of the C++ standard.

Template parameters
Parameter Description
Arg1 project1st's first argument type, and its result type.
Arg2 project1st 's second argument type.
Model of

Adaptable Binary Function

Type requirements

None.

Public base classes

binary_function<Arg1, Arg2, Arg1>

Members
Member Where defined Description
first_argument_type Adaptable Binary Function The type of project1st's first argument: Arg1
second_argument_type Adaptable Binary Function The type of project1st's second argument: Arg2
result_type Adaptable Binary Function The type of the result: Arg1.
Arg1 operator()(const Arg1& x, const Arg2&) const Adaptable Binary Function Function call. The return value is x.
New members

All of project1st's members are defined in the Adaptable Binary Function requirements. project1st does not introduce any new members.

See also

Function objects, identity, project2nd, select1st, select2nd

project2nd<Arg1, Arg2>

Category: functors

Component type: type

Description

Project2nd is a function object that takes two arguments and returns its second argument; the first argument is unused. It is essentially a generalization of identity to the

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

0

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

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