function template
std::operators (forward_list)
<forward_list>
(1) | template <class T, class Alloc>
bool operator== ( const forward_list<T,Alloc>& lhs, const forward_list<T,Alloc>& rhs );
|
---|
(2) | template <class T, class Alloc>
bool operator!= ( const forward_list<T,Alloc>& lhs, const forward_list<T,Alloc>& rhs );
|
---|
(3) | template <class T, class Alloc>
bool operator< ( const forward_list<T,Alloc>& lhs, const forward_list<T,Alloc>& rhs );
|
---|
(4) | template <class T, class Alloc>
bool operator> ( const forward_list<T,Alloc>& lhs, const forward_list<T,Alloc>& rhs );
|
---|
(5) | template <class T, class Alloc>
bool operator>= ( const forward_list<T,Alloc>& lhs, const forward_list<T,Alloc>& rhs );
|
---|
(6) | template <class T, class Alloc>
bool operator<= ( const forward_list<T,Alloc>& lhs, const forward_list<T,Alloc>& rhs ); |
---|
Relational operators for forward_list
These overloaded global operator functions perform the appropriate comparison operation between the forward_list containers lhs and rhs.
Operations == and != are performed by comparing the elements one by one using algorithm equal, stopping at the first mismatch.
Operations <, >, <= and >= behave as if using algorithm lexicographical_compare, which requires that the type of the elements contained (value_type) has the < operation (less-than) defined between two objects of that type.
These operators are overloaded in header <forward_list>.
Parameters
- lhs, rhs
- forward_list containers (to the left- and right-hand side of the operator, respectively), having both the same template parameters (T and Alloc).
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
// forward_list comparisons
#include <iostream>
#include <forward_list>
int main ()
{
std::forward_list<int> a = {10, 20, 30};
std::forward_list<int> b = {10, 20, 30};
std::forward_list<int> c = {30, 20, 10};
if (a==b) std::cout << "a and b are equal\n";
if (b!=c) std::cout << "b and c are not equal\n";
if (b<c) std::cout << "b is less than c\n";
if (c>b) std::cout << "c is greater than b\n";
if (a<=b) std::cout << "a is less than or equal to b\n";
if (a>=b) std::cout << "a is greater than or equal to b\n";
return 0;
}
|
Output:
a and b are equal
b and c are not equal
b is less than c
c is greater than b
a is less than or equal to b
a is greater than or equal to b
|
Return Value
true if the condition holds, and false otherwise.
Complexity
Linear in both lhs and rhs's sizes.
Iterator validity
No changes.