namespace std {
template<class... TTypes, class... UTypes>
bool operator==(const tuple<TTypes...>& t,
const tuple<UTypes...>& u); // (1) C++11
template<class... TTypes, class... UTypes>
constexpr bool operator==(const tuple<TTypes...>& t,
const tuple<UTypes...>& u); // (1) C++14
template<class... TTypes, tuple-like UTuple>
constexpr bool operator==(const tuple<TTypes...>& t,
const UTuple& u); // (2) C++23
}
概要
2つのtuple
オブジェクトの等値比較を行う。また、tuple-like
なオブジェクトとの等値比較を行う。(C++23以降)
テンプレートパラメータ制約
- (1) :
- (2) :
- C++23 : 2つの
tuple-like
なオブジェクトの要素数が同じであること。(正確には、sizeof...(TTypes) == tuple_size_v<UTuple>
であること。) - C++23 :
tuple
の要素std::get<i>(t)
とtuple-like
なオブジェクトの要素std::get<i>(u)
において、すべての要素の比較std::get<i>(t) == std::get<i>(u)
の比較結果がboolean-testable
を満たす型(bool
へ変換可能な型)であること。
- C++23 : 2つの
効果
0番目の要素から順に等値比較を行う。
戻り値
tuple
の全ての要素をstd::get<i>(t) == std::get<i>(u)
した結果がtrue
である場合true
を返し、そうでなければfalse
を返す。
備考
- この演算子により、以下の演算子が使用可能になる (C++20):
operator!=
例
#include <iostream>
#include <tuple>
#include <string>
int main()
{
std::tuple<int, char, const char*> t1(1, 'a', "hello");
std::tuple<int, char, std::string> t2(1, 'a', "hello");
std::tuple<int, char, std::string> t3(1, 'a', "hellot");
std::cout << std::boolalpha;
{
bool result = t1 == t2; // ※型は異なっていてもかまわない
std::cout << result << std::endl;
}
{
bool result = t1 == t3;
std::cout << result << std::endl;
}
}
出力
true
false
バージョン
言語
- C++11
処理系
- Clang: ??
- GCC: 4.6.1 ✅
- ICC: ??
- Visual C++: ??