friend constexpr bool operator==(partial_ordering v, partial_ordering w) noexcept = default; // (1)
friend constexpr bool operator==(partial_ordering v, /*unspecified*/) noexcept; // (2)
// (2)により、以下のオーバーロードが使用可能になる
friend constexpr bool operator==(/*unspecified*/, partial_ordering v) noexcept; // (3)
概要
- (1) :
partial_ordering
同士の等値比較を行う - (2)(3) :
partial_ordering
の値がpartial_ordering::equivalent
であるかを調べる。
戻り値
int
型のメンバ変数value
に各有効値に対応する値、bool
型メンバ変数is_ordered
に順序付けされているかどうかを保持しているとして、以下と等価
- (1) :
return v.value == w.value && v.is_ordered == w.is_ordered
- (2) :
return v.is_ordered && v.value == 0
- (3) :
return v == 0
例外
投げない。
備考
この演算子により、以下の演算子が使用可能になる:
bool operator!=(partial_ordering v, partial_ordering w) noexcept;
bool operator!=(partial_ordering v, /*unspecified*/) noexcept;
bool operator!=(/*unspecified*/, partial_ordering w) noexcept;
unspecifiedとなっている片側の引数には0
リテラルのみが使用できる。それ以外の物を渡した場合、動作は未定義。
例
#include <iostream>
#include <compare>
int main()
{
std::partial_ordering comp1 = 1 <=> 2;
std::partial_ordering comp2 = 1 <=> 1;
std::partial_ordering comp3 = -0.0 <=> +0.0;
constexpr auto qnan = std::numeric_limits<double>::quiet_NaN();
std::partial_ordering comp4 = qnan <=> qnan;
std::cout << std::boolalpha;
// (1)
std::cout << (comp1 == comp2) << std::endl;
// (2)
std::cout << (comp1 == 0) << std::endl;
std::cout << (comp3 == 0) << std::endl;
std::cout << (comp4 == 0) << std::endl;
// (3)
std::cout << (0 == comp1) << std::endl;
std::cout << (0 == comp3) << std::endl;
std::cout << (0 == comp4) << std::endl;
}
xxxxxxxxxx
#include <iostream>
#include <compare>
int main()
{
std::partial_ordering comp1 = 1 <=> 2;
std::partial_ordering comp2 = 1 <=> 1;
std::partial_ordering comp3 = -0.0 <=> +0.0;
constexpr auto qnan = std::numeric_limits<double>::quiet_NaN();
std::partial_ordering comp4 = qnan <=> qnan;
std::cout << std::boolalpha;
// (1)
std::cout << (comp1 == comp2) << std::endl;
// (2)
std::cout << (comp1 == 0) << std::endl;
std::cout << (comp3 == 0) << std::endl;
std::cout << (comp4 == 0) << std::endl;
// (3)
std::cout << (0 == comp1) << std::endl;
std::cout << (0 == comp3) << std::endl;
std::cout << (0 == comp4) << std::endl;
}
出力
false
false
true
false
false
true
false
バージョン
言語
- C++20
処理系
- Clang: 8.0(1が未実装) ✅
- GCC: 10.1(full support) ✅
- Visual C++: 2019(1が未実装) ✅