- array[meta header]
- std[meta namespace]
- function template[meta id-type]
- cpp11[meta cpp]
namespace std {
template <class T, size_t N>
bool operator==(const array<T, N>& x, const array<T, N>& y); // C++11
template <class T, size_t N>
constexpr bool operator==(const array<T, N>& x, const array<T, N>& y); // C++20
}arrayオブジェクトの等値比較を行う。
型Tがoperator==で等値比較可能であること。
- C++11 :
distance(x.begin(), x.end()) ==distance(y.begin(), y.end()) &&equal(x.begin(), x.end(), y.begin()); - C++14 :
equal(x.begin(), x.end(), y.begin(), y.end());
xとyの要素が全て等値であればtrue、そうでなければfalseを返す。
線形時間
- この演算子により、以下の演算子が使用可能になる (C++20):
operator!=
#include <iostream>
#include <array>
int main()
{
std::array<int, 3> x = {1, 2, 3};
std::array<int, 3> y = {1, 2, 3};
if (x == y) {
std::cout << "equal" << std::endl;
}
else {
std::cout << "not equal" << std::endl;
}
}equal
- C++11
- Clang: ??
- GCC: 4.7.0 [mark verified]
- ICC: ??
- Visual C++: 2008 (std::tr1) [mark verified], 2010 [mark verified], 2012 [mark verified]
- LWG Issue 2257. Simplify container requirements with the new algorithms
- C++14から、2つ目のイテレータ範囲のendイテレータをとる
equal()アルゴリズムを使用するようになった。
- C++14から、2つ目のイテレータ範囲のendイテレータをとる
- P1023R0
constexprcomparison operators forstd::array - P1614R2 The Mothership has Landed
- C++20での三方比較演算子の追加と、関連する演算子の自動導出