Public base classes
binary_function
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
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 case of a Binary Function.
Example
int main() {
vector v1(10, (char*) 0);
vector v2(10, 137);
vector result(10);
transform(v1.begin(), v1.end(), v2.begin(), result.begin(), project2nd());
assert(equal(v2.begin(), v2.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 |
project2nd 's first argument type. |
Arg2 |
project2nd 's second argument type, and its result type. |
Model of
Adaptable Binary Function
Type requirements
None.
Public base classes
binary_function
Members
Member |
Where defined |
Description |
first_argument_type |
Adaptable Binary Function |
The type of project2nd 's first argument: Arg1 |
second_argument_type |
Adaptable Binary Function |
The type of project2nd 's second argument: Arg2 |
result_type |
Adaptable Binary Function |
The type of the result: Arg2 . |
Arg1 operator()(const Arg1&, const Arg2& y) const |
Adaptable Binary Function |
Function call. The return value is y . |
New members
All of project2nd 's members are defined in the Adaptable Binary Function requirements. project2nd does not introduce any new members.
See also
Function objects, identity , project1st , select1st , select2nd
Category: functors
Component type: type
Description
Select1st is a function object that takes a single argument, a pair [1], and returns the pair's first element.
Example
Print all of a map 's keys.
int main() {
map M;
M[1] = 0.3;
M[47] = 0.8;
M[33] = 0.1;
transform(M.begin(), M.end(), ostream_iterator(cout, " "), select1st::value_type>());
// The output is 1 33 47.
}
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 |
Pair |
The function object's argument type. |
Model of
Adaptable Unary Function
Type requirements
There exist some types U and V such that Pair provides the same interface as a pair . [1]
Public base classes
unary_function
Members
Member |
Where defined |
Description |
argument_type |
Adaptable Unary Function |
The type of select1st 's argument: Pair |
result_type |
Adaptable Unary Function The type of the result: |
Pair::first_type |
const Pair::first_type& operator()(const Pair& p) const |
Adaptable Unary Function |
Function call. The return value is p.first . |
New members
All of select1st 's members are defined in the Adaptable Unary Function requirements. Select1st does not introduce any new members.
Notes
[1] Pair is not actually required to be a pair , but merely to support the same interface as pair . In almost all cases the template parameter will be a pair , but it is occasionally useful for it to be something else. One example is a struct that has the members first , second , and third .
See also
identity , select2nd , project1st , project2nd
Category: functors
Component type: type
Description
Select2nd is a function object that takes a single argument, a pair [1], and returns the pair's second element.
Example
Print all of a map 's values.
int main() {
map M;
M[1] = 0.3;
M[47] = 0.8;
M[33] = 0.1;
transform(M.begin(), M.end(), ostream_iterator(cout, " "), select2nd::value_type>());
// The output is 0.3 0.1 0.8
}
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 |
Pair |
The function object's argument type. |
Model of
Adaptable Unary Function
Читать дальше