std::weak_ordering
From cppreference.com
| ヘッダ <compare> で定義 |
||
| class weak_ordering; |
(C++20以降) | |
クラス型std::weak_orderingは、三項比較の結果型であり、
- 6つの関係演算子 (
==,!=,<,<=,>,>=) をすべて許容します。
- 置換可能性を意味しません。つまり、
aがbと等価であっても、f(a)はf(b)と等価ではない場合があります。ここで、fは引数のパブリックconstメンバを通じてアクセス可能な比較に関連する状態のみを読み取る関数です。言い換えると、等価な値は区別可能である可能性があります。 - 比較不能な値を許容しません。
a < b、a == b、またはa > bのいずれか1つのみがtrueである必要があります。
目次 |
[編集] 定数
型std::weak_orderingには、その型のconst staticデータメンバとして実装された3つの有効な値があります。
| 名前 | 定義 |
| inline constexpr std::weak_ordering less [static] |
より小さい(順序が前)関係を示す有効な値 (公開静的メンバ定数) |
| inline constexpr std::weak_ordering equivalent [static] |
等価であることを示す有効な値(順序付けられても、順序付けられていなくてもよい) (公開静的メンバ定数) |
| inline constexpr std::weak_ordering greater [static] |
より大きい(順序が後)関係を示す有効な値 (公開静的メンバ定数) |
[編集] 変換
std::weak_orderingはstd::partial_orderingに暗黙的に変換可能ですが、std::strong_orderingはweak_orderingに暗黙的に変換可能です。
| operator partial_ordering |
std::partial_orderingへの暗黙変換(public member function) |
std::weak_ordering::operator partial_ordering
| constexpr operator partial_ordering() const noexcept; |
||
戻り値
vがlessの場合はstd::partial_ordering::less、vがgreaterの場合はstd::partial_ordering::greater、vがequivalentの場合はstd::partial_ordering::equivalent。
[編集] 比較
この型の値とリテラルの0との間で比較演算子が定義されています。これにより、三項比較演算子の結果をブール関係に変換するために使用できる式 a <=> b == 0 または a <=> b < 0 をサポートします。詳細はstd::is_eq、std::is_ltなどを参照してください。
これらの関数は、通常の非修飾または修飾検索では表示されず、std::weak_orderingが引数に関連付けられたクラスである場合にのみ引数依存検索で見つけることができます。
weak_orderingを整数リテラル0以外のものと比較しようとするプログラムの動作は未定義です。
| operator==operator<operator>operator<=operator>=operator<=> |
ゼロまたはweak_orderingとの比較(関数) |
operator==
| friend constexpr bool operator==( weak_ordering v, /*未指定*/ u ) noexcept; |
(1) | |
| friend constexpr bool operator==( weak_ordering v, weak_ordering w ) noexcept = default; |
(2) | |
パラメータ
| v, w | - | チェックするstd::weak_ordering値 |
| u | - | リテラルゼロ引数を受け入れる任意の型の未使用パラメータ |
戻り値
1)
vがequivalentの場合はtrue、vがlessまたはgreaterの場合はfalse。両方のパラメータが同じ値を持つ場合は
true、それ以外の場合はfalse。operator<
| friend constexpr bool operator<( weak_ordering v, /*未指定*/ u ) noexcept; |
(1) | |
| friend constexpr bool operator<( /*未指定*/ u, weak_ordering v ) noexcept; |
(2) | |
パラメータ
| v | - | チェックするstd::weak_ordering値 |
| u | - | リテラルゼロ引数を受け入れる任意の型の未使用パラメータ |
戻り値
vがlessの場合はtrue、vがgreaterまたはequivalentの場合はfalse。vがgreaterの場合はtrue、vがlessまたはequivalentの場合はfalse。operator<=
| friend constexpr bool operator<=( weak_ordering v, /*未指定*/ u ) noexcept; |
(1) | |
| friend constexpr bool operator<=( /*未指定*/ u, weak_ordering v ) noexcept; |
(2) | |
パラメータ
| v | - | チェックするstd::weak_ordering値 |
| u | - | リテラルゼロ引数を受け入れる任意の型の未使用パラメータ |
戻り値
vがlessまたはequivalentの場合はtrue、vがgreaterの場合はfalse。vがgreaterまたはequivalentの場合はtrue、vがlessの場合はfalse。operator>
| friend constexpr bool operator>( weak_ordering v, /*未指定*/ u ) noexcept; |
(1) | |
| friend constexpr bool operator>( /*未指定*/ u, weak_ordering v ) noexcept; |
(2) | |
パラメータ
| v | - | チェックするstd::weak_ordering値 |
| u | - | リテラルゼロ引数を受け入れる任意の型の未使用パラメータ |
戻り値
vがgreaterの場合はtrue、vがlessまたはequivalentの場合はfalse。vがlessの場合はtrue、vがgreaterまたはequivalentの場合はfalse。operator>=
| friend constexpr bool operator>=( weak_ordering v, /*未指定*/ u ) noexcept; |
(1) | |
| friend constexpr bool operator>=( /*未指定*/ u, weak_ordering v ) noexcept; |
(2) | |
パラメータ
| v | - | チェックするstd::weak_ordering値 |
| u | - | リテラルゼロ引数を受け入れる任意の型の未使用パラメータ |
戻り値
vがgreaterまたはequivalentの場合はtrue、vがlessの場合はfalse。vがlessまたはequivalentの場合はtrue、vがgreaterの場合はfalse。operator<=>
| friend constexpr weak_ordering operator<=>( weak_ordering v, /*未指定*/ u ) noexcept; |
(1) | |
| friend constexpr weak_ordering operator<=>( /*未指定*/ u, weak_ordering v ) noexcept; |
(2) | |
パラメータ
| v | - | チェックするstd::weak_ordering値 |
| u | - | リテラルゼロ引数を受け入れる任意の型の未使用パラメータ |
戻り値
1) v。
2)
vがlessの場合はgreater、greaterの場合はless、それ以外の場合はv。[編集] 例
| このセクションは未完成です 理由: 例がありません |
[編集] 関連項目
| (C++20) |
6つすべての演算子をサポートし、置換可能である三方比較の結果型 (クラス) |
| (C++20) |
6つすべての演算子をサポートし、置換可能ではなく、比較不可能な値を許容する三方比較の結果型 (クラス) |