diff --git a/reference/expected/expected.md b/reference/expected/expected.md index 018ba2380..21b53d030 100644 --- a/reference/expected/expected.md +++ b/reference/expected/expected.md @@ -69,8 +69,8 @@ namespace std { | 名前 | 説明 | 対応バージョン | |--------------|------------|-------| -| [`operator==`](unexpected/op_equal.md.nolink) | 等値比較 | C++23 | -| [`operator!=`](unexpected/op_not_equal.md.nolink) | 非等値比較 | C++23 | +| [`operator==`](expected/op_equal.md) | 等値比較 | C++23 | +| [`operator!=`](expected/op_not_equal.md) | 非等値比較 | C++23 | ## メンバ型 diff --git a/reference/expected/expected/op_equal.md b/reference/expected/expected/op_equal.md new file mode 100644 index 000000000..efbb18770 --- /dev/null +++ b/reference/expected/expected/op_equal.md @@ -0,0 +1,95 @@ +# operator== +* expected[meta header] +* function template[meta id-type] +* std[meta namespace] +* expected[meta class] +* cpp23[meta cpp] + +```cpp +template requires (!is_void_v) +friend constexpr bool operator==(const expected& x, const expected& y); // (1) + +template +friend constexpr bool operator==(const expected& x, const T2& v); // (2) +// (2)により、下記オーバーロードが使用可能になる +template +friend constexpr bool operator==(const T2& v, const expected& x); // (3) + +template +friend constexpr bool operator==(const expected& x, const unexpected& e); // (4) +// (4)により、下記オーバーロードが使用可能になる +template +friend constexpr bool operator==(const unexpected& e, const expected& x); // (5) +``` +* is_void_v[link /reference/type_traits/is_void.md] +* unexpected[link ../unexpected.md] + +## 概要 +- (1) : `unexpected`オブジェクト同士の等値比較を行う。 +- (2), (3) : `unexpected`オブジェクトと正常値の等値比較を行う。 +- (4), (5) : `unexpected`オブジェクトとエラー値の等値比較を行う。 + + +## 適格要件 +- (1) : 式[`*x`](op_deref.md) `==` [`*y`](op_deref.md)および式`x.`[`error()`](error.md) `== y.`[`error()`](error.md)が適格であり、各式の結果を`bool`へ変換可能であること。 +- (2), (3) : 式[`*x`](op_deref.md) `== v`が適格であり、その結果を`bool`へ変換可能であること。 +- (4), (5) : 式`x.`[`error()`](error.md) `== e.`[`error()`](../unexpected/error.md.nolink)が適格であり、その結果を`bool`へ変換可能であること。 + + +## 戻り値 +- (1) : 次の値を返す + - `x.`[`has_value()`](has_value.md)と`y.`[`has_value()`](has_value.md)が異なるとき、`false` + - `x.`[`has_value()`](has_value.md) `== true`のとき、[`*x`](op_deref.md) `==` [`*y`](op_deref.md) + - `x.`[`error()`](error.md) `== y.`[`error()`](error.md) +- (2), (3) : `x.`[`has_value()`](has_value.md) `&& static_cast(`[`*x`](op_deref.md) `== v)` +- (4), (5) : `!x.`[`has_value()`](has_value.md) `&& static_cast(x.`[`error()`](error.md) `== e.`[`error()`](../unexpected/error.md.nolink)`)` + + +## 例 +```cpp example +#include +#include + +int main() +{ + std::expected x1 = 1; + std::expected y1 = 1; + std::expected x2 = std::unexpected{1}; + std::expected y2 = std::unexpected{1}; + + // (1) + assert(x1 == y1); + assert(x2 == y2); + assert(not (x1 == y2)); + assert(not (x2 == y1)); + + // (2), (3) + assert(x1 == 1); + assert(1 == x1); + + // (4), (5) + assert(x2 == std::unexpected{1}); + assert(std::unexpected{1} == x2); +} +``` +* ==[color ff0000] +* std::unexpected[link ../unexpected.md] + +### 出力 +``` +``` + + +## バージョン +### 言語 +- C++23 + +### 処理系 +- [Clang](/implementation.md#clang): 16.0 +- [GCC](/implementation.md#gcc): 12.1 +- [ICC](/implementation.md#icc): ?? +- [Visual C++](/implementation.md#visual_cpp): ?? + + +## 参照 +- [P0323R12 std::expected](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p0323r12.html) diff --git a/reference/expected/expected/op_not_equal.md b/reference/expected/expected/op_not_equal.md new file mode 100644 index 000000000..dc9fb7370 --- /dev/null +++ b/reference/expected/expected/op_not_equal.md @@ -0,0 +1,92 @@ +# operator!= +* expected[meta header] +* function template[meta id-type] +* std[meta namespace] +* expected[meta class] +* cpp23[meta cpp] + +```cpp +// operator==により、下記オーバーロードが使用可能になる +template requires (!is_void_v) +friend constexpr bool operator!=(const expected& x, const expected& y); // (1) + +template +friend constexpr bool operator!=(const expected& x, const T2& v); // (2) +template +friend constexpr bool operator!=(const T2& v, const expected& x); // (3) + +template +friend constexpr bool operator!=(const expected& x, const unexpected& e); // (4) +template +friend constexpr bool operator!=(const unexpected& e, const expected& x); // (5) +``` +* operator==[link op_equal.md] +* is_void_v[link /reference/type_traits/is_void.md] +* unexpected[link ../unexpected.md] + +## 概要 +- (1) : `unexpected`オブジェクト同士の非等値比較を行う。 +- (2), (3) : `unexpected`オブジェクトと正常値の非等値比較を行う。 +- (4), (5) : `unexpected`オブジェクトとエラー値の非等値比較を行う。 + + +## 適格要件 +- (1) : 式[`*x`](op_deref.md) `==` [`*y`](op_deref.md)および式`x.`[`error()`](error.md) `== y.`[`error()`](error.md)が適格であり、各式の結果を`bool`へ変換可能であること。 +- (2), (3) : 式[`*x`](op_deref.md) `== v`が適格であり、その結果を`bool`へ変換可能であること。 +- (4), (5) : 式`x.`[`error()`](error.md) `== e.`[`error()`](../unexpected/error.md.nolink)が適格であり、その結果を`bool`へ変換可能であること。 + + +## 戻り値 +- (1) : `!`[`(x == y)`](op_equal.md) +- (2), (3) : `!`[`(x == v)`](op_equal.md) +- (4), (5) : `!`[`(x == e)`](op_equal.md) + + +## 例 +```cpp example +#include +#include + +int main() +{ + std::expected x1 = 1; + std::expected y1 = 100; + std::expected x2 = std::unexpected{1}; + std::expected y2 = std::unexpected{100}; + + // (1) + assert(x1 != y1); + assert(x2 != y2); + assert(x1 != y2); + assert(x2 != y1); + + // (2), (3) + assert(x1 != 2); + assert(2 != x1); + + // (4), (5) + assert(x2 != std::unexpected{2}); + assert(std::unexpected{2} != x2); +} +``` +* !=[color ff0000] +* std::unexpected[link ../unexpected.md] + +### 出力 +``` +``` + + +## バージョン +### 言語 +- C++23 + +### 処理系 +- [Clang](/implementation.md#clang): 16.0 +- [GCC](/implementation.md#gcc): 12.1 +- [ICC](/implementation.md#icc): ?? +- [Visual C++](/implementation.md#visual_cpp): ?? + + +## 参照 +- [P0323R12 std::expected](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p0323r12.html)