(where T is convertible to bool) then f(x,y) returns true if and only if both x and y are true. [1]

Example

Finds the first element in a list that lies in the range from 1 to 10.

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

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_and's arguments
Model of

Adaptable Binary Predicate, DefaultConstructible

Type requirements

T must be convertible to bool.

Public base classes

binary_function<T, T, bool>

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_and() Default Constructible The default constructor.
New members

All of logical_and's members are defined in the Adaptable Binary Function and Default Constructible requirements. Logical_and 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_or, logical_not.

logical_or<T>

Category: functors

Component type: type

Description

Logical_or<T> is a function object; specifically, it is an Adaptable Binary 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_and<T> and x and y are objects of class T (where T is convertible to bool) then f(x,y) returns true if and only if either x or y is true. [1]

Example

Finds the first instance of either ' ' or ' ' in a string.

char str[MAXLEN];

const char* wptr = find_if(str, str + MAXLEN, compose2(logical_or<bool>(), bind2nd (equal_to<char>(), ' '), bind2nd(equal_to<char>(), ' ')));

assert(wptr == str + MAXLEN || *wptr == ' ' || *wptr == ' ');

Definition

Defined in the standard header functional, and in the nonstandard backward-compatibility header

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

0

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

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