函式模板
<forward_list>

std::關係運算符 (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);
forward_list 的關係運算符
lhsrhs 這兩個 forward_list 容器執行適當的比較操作。

相等比較 (operator==) 透過順序比較元素(使用 operator==)來執行,在第一個不匹配處停止(如同使用演算法 equal)。

小於比較 (operator<) 的行為如同使用演算法 lexicographical_compare,該演算法透過順序比較元素(使用 operator<)以相對的方式進行(即,同時檢查 a<bb<a),並在第一次出現時停止。

其他操作也使用 ==< 運算子在內部比較元素,其行為如同執行了以下等效操作:
操作等效操作
a!=b!(a==b)
a>bb<a
a<=b!(b<a)
a>=b!(a<b)

這些運算子在標頭檔案 <forward_list> 中進行了過載。

引數

lhs, rhs
forward_list 容器(分別位於運算子的左側和右側),它們具有相同的模板引數(TAlloc).

示例

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

輸出
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


返回值

如果條件成立,則為 true,並且否則為 false。

複雜度

最多與 lhsrhs 的大小成線性關係。

迭代器有效性

沒有變化。

資料競爭

lhsrhs 這兩個容器都會被訪問。
最多可以訪問它們包含的所有元素。

異常安全

如果元素的型別支援適當的操作且無異常保證,則該函式永遠不會丟擲異常(無異常保證)。
在任何情況下,該函式都不能修改其引數。

另見