C++ Reference: Standard C++ Library reference: Containers: deque: deque: operators

C++官网参考链接:https://cplusplus.com/reference/deque/deque/operators/

函数
<deque>
std::relational operators (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==)是通过第一次比较sizes来执行的,如果它们匹配,则使用operator==对元素进行顺序比较,在第一次不匹配时停止(就像使用算法equal)。
小于比较(operator<)的行为类似于使用算法lexicographical_compare,它以互反的方式使用operator<依次比较元素(即检查a<b和b<a)并在第一次出现时停止。
其他操作也在内部使用操作符==和<来比较元素,就像执行了以下等价操作一样:

operationequivalent operation
a!=b!(a==b)
a>bb<a
a<=b!(b<a)
a>=b!(a<b)

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

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

用例
// 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;
}
输出:

返回值
如果条件成立,则为true,否则为false。

复杂度
C++98
最多达到lhs和rhs的size中的线性。
C++14
对于(1)和(2),如果lhs和rhs的sizes不同,则为常量,否则最多为size(相等比较)中的线性。
对于其它的,最多达到较小的size中的线性(每一个表示具有operator<的两次比较)。

iterator的有效性
没有变化。

数据竞争
两个容器lhs和rhs都被访问。
它们所包含的所有元素都可以被访问。

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

weixin_40186813

你的能量无可限量。

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值