namespace std {
template <class T, class Allocator>
bool operator==(const deque<T, Allocator>& x, const deque<T, Allocator>& y);
}
概要
deque
オブジェクトの等値比較を行う。
要件
型T
が==
で比較可能であること。
効果
-
C++03 :
-
C++14 :
戻り値
x
とy
の要素数および要素の値が等しければtrue
、そうでなければfalse
を返す。
計算量
x.size()
に対して線形時間。ただし、x
とy
のサイズが異なる場合は定数時間。
例
#include <iostream>
#include <deque>
int main ()
{
std::deque<int> c1 = {1, 2, 3};
std::deque<int> c2 = {1, 2, 3};
std::deque<int> c3 = {1, 2, 3, 4};
std::cout << std::boolalpha;
// 要素数と要素の値が等しい
std::cout << (c1 == c2) << std::endl;
// 要素の値は(左辺の要素数分まで)等しいが要素数が異なる
std::cout << (c1 == c3) << std::endl;
}
出力
true
false
参照
- LWG Issue 2257. Simplify container requirements with the new algorithms
- C++14から、2つ目の範囲のendイテレータをとる
equal()
アルゴリズムを使用するようになった。
- C++14から、2つ目の範囲のendイテレータをとる