GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • cpprefjp - C++日本語リファレンス
  • GitHub Project

This view

  • Original page
  • New address

GeezerVison is showing cpprefjp.github.io — std::operator== - cpprefjp C++日本語リファレンス

  1. リファレンス
  2. array
  3. array
  4. operator==

最終更新日時: 2026年09月19日 21時31分51秒 (JST)
rotarymars が更新

履歴 編集

function template
<array>

std::operator==(C++11)

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: 9.0.1 ✅
  • GCC: 4.7.0 ✅
  • Visual C++: 2008 (std::tr1) ✅, 2010 ✅, 2012 ✅

参照

  • LWG Issue 2257. Simplify container requirements with the new algorithms
    • C++14から、2つ目のイテレータ範囲のendイテレータをとるequal()アルゴリズムを使用するようになった。
  • P1023R0 constexpr comparison operators for std::array
  • P1614R2 The Mothership has Landed
    • C++20での三方比較演算子の追加と、関連する演算子の自動導出
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.