template <class U, class AA>
friend constexpr bool operator==(
const indirect& lhs, const indirect<U, AA>& rhs) noexcept(see below); // (1)
template <class U>
friend constexpr bool operator==(
const indirect& lhs, const U& rhs) noexcept(see below); // (2)
概要
- (1) : 2つの
indirectオブジェクトが所有する値を等値比較する。 - (2) :
indirectオブジェクトが所有する値と、別の値rhsを等値比較する。
いずれもHidden friendsとして定義される。
適格要件
戻り値
- (1) :
lhsとrhsのいずれかが無効値状態であればlhs.valueless_after_move() == rhs.valueless_after_move()、そうでなければ*lhs == *rhs。 - (2) :
lhsが無効値状態であればfalse、そうでなければ*lhs == rhs。
例外
noexcept指定は下記の式に従う。
- (1) :
noexcept(bool(*lhs == *rhs)) - (2) :
noexcept(bool(*lhs == rhs))
備考
この演算子により、operator!=が使用可能になる。
例
#include <cassert>
#include <memory>
int main()
{
std::indirect<int> a{42};
std::indirect<int> b{42};
assert(a == b); // (1) indirect同士の比較
assert(a == 42); // (2) 値との比較
assert(a != 0);
}
出力
バージョン
言語
- C++26
処理系
- Clang: 22 ❌
- GCC: 16.1 ✅
- Visual C++: 2026 Update 2 ❌
関連項目
参照
- P3019R14
indirectandpolymorphic: Vocabulary Types for Composite Class Design - LWG Issue 4325.
std::indirect'soperator==still doesn't support incomplete types- C++26で、
noexcept指定をboolへの変換を含む式bool(*lhs == *rhs)にもとづくよう修正した
- C++26で、