Public base classes
binary_function
Members
Member |
Where defined |
Description |
first_argument_type |
Adaptable Binary Function |
The type of the first argument: T |
second_argument_type |
Adaptable Binary Function |
The type of the second argument: T |
result_type |
Adaptable Binary Function |
The type of the result: bool |
bool operator()(const T& x, const T& y) const |
Binary Function Function |
call operator. The return value is x || y . |
logical_or() |
Default Constructible |
The default constructor. |
New members
All of logical_or 's members are defined in the Adaptable Binary Function and Default Constructible requirements. Logical_or does not introduce any new members.
Notes
[1] Logical_and and logical_or are not very useful by themselves. They are mainly useful because, when combined with the function object adaptor binary_compose , they perform logical operations on other function objects.
See also
The function object overview, logical_and , logical_not .
Category: functors
Component type: type
Description
Logical_not is a function object; specifically, it is an Adaptable Predicate, which means it is a function object that tests the truth or falsehood of some condition. If f is an object of class logical_not and x is an object of class T (where T is convertible to bool ) then f(x) returns true if and only if x is false .
Example
Transforms a vector of bool into its logical complement.
vector V;
…
transform(V.begin(), V.end(), V.begin(), logical_not());
Definition
Defined in the standard header functional, and in the nonstandard backward-compatibility header function.h.
Template parameters
Parameter |
Description |
T |
The type of logical_not 's argument |
Model of
Adaptable Predicate, DefaultConstructible
Type requirements
T must be convertible to bool .
Public base classes
unary_function
Members
Member |
Where defined |
Description |
argument_type |
Adaptable Unary Function |
The type of the second argument: T |
result_type |
Adaptable Unary Function |
The type of the result: bool |
bool operator()(const T& x) const |
Unary Function Function call operator. |
The return value is !x . |
logical_not() |
Default Constructible |
The default constructor. |
See also
The function object overview, logical_or , logical_and .
Generalized identity operations
Category: functors
Component type: type
Description
Identity is a Unary Function that represents the identity function: it takes a single argument x , and returns x .
Example
int main() {
int x = 137;
identity id;
assert(x == id(x));
}
Definition
Defined in the standard header functional, and in the nonstandard backward-compatibility header function.h. This class is an SGI extension; it is not part of the C++ standard.
Template parameters
Parameter |
Description |
T |
The function object's argument type, and return type. [1] |
Model of
Adaptable Unary Function
Type requirements
None.
Public base classes
unary_function
Members
Member |
Where defined |
Description |
argument_type |
Adaptable Unary Function |
The type of identity 's argument: T . |
result_type |
Adaptable Unary Function |
The type of the result: T . [1] |
const T& operator()(const T&) const |
Adaptable Unary Function |
Function call. The return value is simply the argument. |
New members
All of identity 's members are defined in the Adaptable Unary Function 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
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 v1(10, 137);
vector v2(10, (char*) 0);
vector result(10);
transform(v1.begin(), v1.end(), v2.begin(), result.begin(), project1st());
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.
Читать дальше