forked from cpprefjp/site
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
C++26対応としてreference_wrapperのoperator==と<=>を追加 cpprefjp#1340
- Loading branch information
1 parent
2d80797
commit 9437e4e
Showing
4 changed files
with
218 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
reference/functional/reference_wrapper/op_compare_3way.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
# operator<=> | ||
* functional[meta header] | ||
* std[meta namespace] | ||
* reference_wrapper[meta class] | ||
* function template[meta id-type] | ||
|
||
```cpp | ||
friend constexpr synth-three-way-result<T> | ||
operator<=>(reference_wrapper x, | ||
reference_wrapper y); // (1) C++26 | ||
|
||
friend constexpr synth-three-way-result<T> | ||
operator<=>(reference_wrapper x, | ||
const T& y); // (2) C++26 | ||
|
||
friend constexpr synth-three-way-result<T> | ||
operator<=>(reference_wrapper x, | ||
reference_wrapper<const T> y); // (3) C++26 | ||
``` | ||
|
||
## 概要 | ||
三方比較を行う。 | ||
|
||
- (1) : 同じ要素型の`reference_wrapper`同士を三方比較する | ||
- (2) : `reference_wrapper`と要素型`T`を三方比較する | ||
- (3) : `reference_wrapper<T>`と`reference_wrapper<const T>`を三方比較する | ||
|
||
(2)と(3)はオペランドを左右で逆にしても使用できる。 | ||
|
||
|
||
## テンプレートパラメータ制約 | ||
- (3) : [`is_const_v`](/reference/type_traits/is_const.md)`<T>`が`false`であること | ||
|
||
|
||
## 戻り値 | ||
- (1) : | ||
```cpp | ||
return synth-three-way(x.get(), y.get()); | ||
``` | ||
* get()[link get.md] | ||
|
||
- (2) : | ||
```cpp | ||
return synth-three-way(x.get(), y); | ||
``` | ||
* get()[link get.md] | ||
|
||
- (3) : | ||
```cpp | ||
return synth-three-way(x.get(), y.get()); | ||
``` | ||
* get()[link get.md] | ||
|
||
|
||
## 備考 | ||
- この演算子により、以下の演算子が使用可能になる: | ||
- `operator<` | ||
- `operator<=` | ||
- `operator>` | ||
- `operator>=` | ||
|
||
|
||
## 例 | ||
```cpp example | ||
#include <cassert> | ||
#include <compare> | ||
#include <functional> | ||
|
||
int main() | ||
{ | ||
int x = 3; | ||
int y = 3; | ||
int z = 4; | ||
|
||
assert((std::ref(x) <=> std::ref(y)) == 0); | ||
assert(std::ref(x) < std::ref(z)); | ||
assert(std::ref(x) <= std::ref(z)); | ||
assert(std::ref(z) > std::ref(x)); | ||
assert(std::ref(z) >= std::ref(x)); | ||
|
||
assert((std::ref(x) <=> 3) == 0); | ||
assert((3 <=> std::ref(x)) == 0); | ||
|
||
assert((std::ref(x) <=> std::cref(y)) == 0); | ||
assert((std::cref(x) <=> std::ref(y)) == 0); | ||
} | ||
``` | ||
|
||
### 出力 | ||
``` | ||
``` | ||
|
||
## バージョン | ||
### 言語 | ||
- C++26 | ||
|
||
### 処理系 | ||
- [Clang](/implementation.md#clang): 11.0 [mark verified] | ||
- [GCC](/implementation.md#gcc): 10 [mark verified] | ||
- [Visual C++](/implementation.md#visual_cpp): 2019 [mark verified] | ||
|
||
|
||
## 参照 | ||
- [P2944R3 Comparisons for `reference_wrapper`](https://open-std.org/jtc1/sc22/wg21/docs/papers/2024/p2944r3.html) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
# operator== | ||
* functional[meta header] | ||
* std[meta namespace] | ||
* reference_wrapper[meta class] | ||
* function template[meta id-type] | ||
|
||
```cpp | ||
friend constexpr bool | ||
operator==(reference_wrapper x, | ||
reference_wrapper y); // (1) C++26 | ||
|
||
friend constexpr bool | ||
operator==(reference_wrapper x, | ||
const T& y); // (2) C++26 | ||
|
||
friend constexpr bool | ||
operator==(reference_wrapper x, | ||
reference_wrapper<const T> y); // (3) C++26 | ||
``` | ||
|
||
## 概要 | ||
等値比較を行う。 | ||
|
||
- (1) : 同じ要素型の`reference_wrapper`同士を等値比較する | ||
- (2) : `reference_wrapper`と要素型`T`を等値比較する | ||
- (3) : `reference_wrapper<T>`と`reference_wrapper<const T>`を等値比較する | ||
|
||
(2)と(3)はオペランドを左右で逆にしても使用できる。 | ||
|
||
|
||
## テンプレートパラメータ制約 | ||
- (1) : 式`x.`[`get()`](get.md) `== y.`[`get()`](get.md)が妥当であり、その戻り値型が`bool`に変換可能であること | ||
- (2) : 式`x.`[`get()`](get.md) `== y`が妥当であり、その戻り値型が`bool`に変換可能であること | ||
- (3) : 式`x.`[`get()`](get.md) `== y.`[`get()`](get.md)が妥当であり、その戻り値型が`bool`に変換可能であること | ||
|
||
|
||
## 戻り値 | ||
- (1) : | ||
```cpp | ||
return x.get() == y.get(); | ||
``` | ||
* get()[link get.md] | ||
|
||
- (2) : | ||
```cpp | ||
return x.get() == y; | ||
``` | ||
* get()[link get.md] | ||
|
||
- (3) : | ||
```cpp | ||
return x.get() == y.get(); | ||
``` | ||
* get()[link get.md] | ||
|
||
|
||
## 備考 | ||
- この演算子により、以下の演算子が使用可能になる: | ||
- `operator!=` | ||
|
||
|
||
## 例 | ||
```cpp example | ||
#include <cassert> | ||
#include <functional> | ||
|
||
int main() | ||
{ | ||
int x = 3; | ||
int y = 3; | ||
|
||
assert(std::ref(x) == std::ref(y)); | ||
|
||
assert(std::ref(x) == 3); | ||
assert(3 == std::ref(x)); | ||
|
||
assert(std::ref(x) == std::cref(y)); | ||
assert(std::cref(x) == std::ref(y)); | ||
} | ||
``` | ||
* std::ref[link /reference/functional/ref.md] | ||
* std::cref[link /reference/functional/cref.md] | ||
|
||
### 出力 | ||
``` | ||
``` | ||
|
||
## バージョン | ||
### 言語 | ||
- C++26 | ||
|
||
### 処理系 | ||
- [Clang](/implementation.md#clang): 3.0 [mark verified] | ||
- [GCC](/implementation.md#gcc): 4.4 [mark verified] | ||
- [Visual C++](/implementation.md#visual_cpp): 2019 [mark verified] | ||
|
||
|
||
## 参照 | ||
- [P2944R3 Comparisons for `reference_wrapper`](https://open-std.org/jtc1/sc22/wg21/docs/papers/2024/p2944r3.html) |