Home C&C++函数库 c++ 语法 程序源码 Linux C库

std::

:relational operators (deque)

函数  <deque>
(1)
template <class T, class Alloc>
  bool operator== (const deque<T,Alloc>& lhs, const deque<T,Alloc>& rhs);
(2)
template <class T, class Alloc>
  bool operator!= (const deque<T,Alloc>& lhs, const deque<T,Alloc>& rhs);
(3)
template <class T, class Alloc>
  bool operator<  (const deque<T,Alloc>& lhs, const deque<T,Alloc>& rhs);
(4)
template <class T, class Alloc>
  bool operator<= (const deque<T,Alloc>& lhs, const deque<T,Alloc>& rhs);
(5)
template <class T, class Alloc>
  bool operator>  (const deque<T,Alloc>& lhs, const deque<T,Alloc>& rhs);
(6)
template <class T, class Alloc>
  bool operator>= (const deque<T,Alloc>& lhs, const deque<T,Alloc>& rhs);
deque的关系操作符

在deque容器lhs和rhs之间执行相应的比较操作。

相等比较(operator==)通过首先比较大小执行,如果匹配, 则使用operator==顺序比较元素,在第一次不匹配时停止(就像使用algorithm equal一样)。

小于比较(操作符<)的行为就像使用算法lexicographal_compare, 它使用操作符<以对等的方式顺序比较元素(即,检查a<b和b<a),并在第一次为真时停止。

其他操作也在内部使用操作符==和<来比较元素,就像执行了以下等价操作一样:
操作符 等价操作
a!=b !(a==b)
a>b b<a
a<=b !(b<a)
a>=b !(a<b)

这些操作符在头文件<deque>中重载。

☲  参数


lhs, rhs
具有相同模板形参(T和Alloc)的deque容器(分别位于操作符的左边和右边)。

☉  返回值



如果条件成立,则为真,否则为假。

☣  示例



// deque comparisons
#include <iostream>
#include <deque>

int main ()
{
  std::deque<int> foo (3,100);   // three ints with a value of 100
  std::deque<int> bar (2,200);   // two ints with a value of 200

  if (foo==bar) std::cout << "foo and bar are equal\n";
  if (foo!=bar) std::cout << "foo and bar are not equal\n";
  if (foo< bar) std::cout << "foo is less than bar\n";
  if (foo> bar) std::cout << "foo is greater than bar\n";
  if (foo<=bar) std::cout << "foo is less than or equal to bar\n";
  if (foo>=bar) std::cout << "foo is greater than or equal to bar\n";

  return 0;
}

输出:
foo and bar are not equal
foo is less than bar
foo is less than or equal to bar

✥ 复杂度


c++98
在lhs和rhs的大小上达到线性。
c++14
对于(1)和(2),如果lhs和rhs的大小不同,则为常数,否则为线性(相等比较)。
对于其他运算符,最小值为线性(每个运算符表示两个 operator<的比较)。

☣ 迭代器的有效性



不变

⇄ 数据竞争


两个容器(lhs和rhs)都被访问。
它们所包含的所有元素都可以被访问。

☂ 异常安全性



如果元素的类型支持有no-throw保证的适当操作,则函数永远不会抛出异常(no-throw保证)。
在任何情况下,函数都不能修改它的参数。

🍄  另请参阅



deque::operator= 分配的内容(公众成员函数)
deque::swap 交换内容(公众成员函数)

联系我们 免责声明 关于CandCplus 网站地图