Skip to content

Commit

Permalink
basic_const_iterator : 残りの比較演算子の追加 #1084
Browse files Browse the repository at this point in the history
  • Loading branch information
onihusube committed Aug 9, 2023
1 parent c925d35 commit 3f6f9ce
Show file tree
Hide file tree
Showing 5 changed files with 440 additions and 8 deletions.
16 changes: 8 additions & 8 deletions reference/iterator/basic_const_iterator.md
Expand Up @@ -32,10 +32,10 @@ namespace std {
| [`operator[]`](basic_const_iterator/op_at.md) | 任意の位置にランダムアクセスする | C++23 |
| [`operator==`](basic_const_iterator/op_equal.md) | 等値比較 | C++23 |
| `operator!=` | 非等値比較 ([`==`](basic_const_iterator/op_equal.md)により使用可能) | C++23 |
| [`operator<`](basic_const_iterator/op_less.md.nolink) | 左辺が右辺より小さいかの判定を行う | C++23 |
| [`operator<=`](basic_const_iterator/op_less_equal.md.nolink) | 左辺が右辺以下かの判定を行う | C++23 |
| [`operator>`](basic_const_iterator/op_greater.md.nolink) | 左辺が右辺より大きいかの判定を行う | C++23 |
| [`operator>=`](basic_const_iterator/op_greater_equal.md.nolink) | 左辺が右辺以上かの判定を行う | C++23 |
| [`operator<`](basic_const_iterator/op_less.md) | 左辺が右辺より小さいかの判定を行う | C++23 |
| [`operator<=`](basic_const_iterator/op_less_equal.md) | 左辺が右辺以下かの判定を行う | C++23 |
| [`operator>`](basic_const_iterator/op_greater.md) | 左辺が右辺より大きいかの判定を行う | C++23 |
| [`operator>=`](basic_const_iterator/op_greater_equal.md) | 左辺が右辺以上かの判定を行う | C++23 |
| [`operator<=>`](basic_const_iterator/op_compare_3way.md) | 三方比較を行う | C++23 |
Expand Down Expand Up @@ -65,10 +65,10 @@ namespace std {
| 名前 | 説明 | 対応バージョン |
|------------------------------------------------------|-------------|-------|
| [`operator<`](basic_const_iterator/op_less.md.nolink) | 左辺が右辺より小さいかの判定を行う | C++23 |
| [`operator<=`](basic_const_iterator/op_less_equal.md.nolink) | 左辺が右辺以下かの判定を行う | C++23 |
| [`operator>`](basic_const_iterator/op_greater.md.nolink) | 左辺が右辺より大きいかの判定を行う | C++23 |
| [`operator>=`](basic_const_iterator/op_greater_equal.md.nolink) | 左辺が右辺以上かの判定を行う | C++23 |
| [`operator<`](basic_const_iterator/op_less.md) | 左辺が右辺より小さいかの判定を行う | C++23 |
| [`operator<=`](basic_const_iterator/op_less_equal.md) | 左辺が右辺以下かの判定を行う | C++23 |
| [`operator>`](basic_const_iterator/op_greater.md) | 左辺が右辺より大きいかの判定を行う | C++23 |
| [`operator>=`](basic_const_iterator/op_greater_equal.md) | 左辺が右辺以上かの判定を行う | C++23 |
| [`operator+`](basic_const_iterator/op_plus.md) | イテレータを進める | C++23 |
| [`operator-`](basic_const_iterator/op_unary_minus.md) | イテレータを逆に進める | C++23 |
| [`operator-`](basic_const_iterator/op_minus.md) | 2つの`basic_const_iterator`の差を求める | C++23 |
Expand Down
108 changes: 108 additions & 0 deletions reference/iterator/basic_const_iterator/op_greater.md
@@ -0,0 +1,108 @@
# operator>
* iterator[meta header]
* std[meta namespace]
* basic_const_iterator[meta class]
* function[meta id-type]
* cpp23[meta cpp]

```cpp
constexpr bool operator>(const basic_const_iterator& y) const
requires random_access_iterator<Iterator>; // (1)

template<different-from<basic_const_iterator> I>
constexpr bool operator>(const I& y) const
requires random_access_iterator<Iterator> && totally_ordered_with<Iterator, I>; // (2)

template<not-a-const-iterator I>
friend constexpr bool operator>(const I& x, const basic_const_iterator& y)
requires random_access_iterator<Iterator> && totally_ordered_with<Iterator, I>; // (3) 非メンバ関数
```
* random_access_iterator[link /reference/iterator/random_access_iterator.md]
* totally_ordered_with[link /reference/concepts/totally_ordered.md]
* different-from[link /reference/ranges/different-from.md]

## 概要

`basic_const_iterator<Iterator>`オブジェクト同士あるいは別のイテレータとの間で、左辺が右辺より大きいかを判定する。

- (1) : 同じ`random_access_iterator`特殊化同士の間の`>`比較
- (2) : `Iterator`と比較可能な型の値との間の`>`比較
- (3) : (2)の逆順の演算子

## テンプレートパラメータ制約

`not-a-const-iterator<I>``I``basic_const_iterator`の特殊化ではない場合に`true`となる説明専用のコンセプトである。

## 効果

ラップしているイテレータを`current_`メンバ変数に保持するとして、以下と等価

- (1) : 以下と等価
```cpp
return current_ > y.current_;
```

- (2) : 以下と等価
```cpp
return current_ > y;
```

- (3) : 以下と等価
```cpp
return x > y.current_;
```

## 備考

(3)の関数は[*Hidden friends*](/article/lib/hidden_friends.md)として定義される。

##
```cpp example
#include <iostream>
#include <iterator>
#include <vector>

int main() {
std::vector vec = {1, 2, 3, 4, 5};

std::basic_const_iterator cit = vec.begin();
auto se = vec.end();
std::basic_const_iterator cse = se;

std::cout << std::boolalpha;

// basic_const_iterator同士の比較
std::cout << (cit > cse) << '\n';
std::cout << (cse > cit) << '\n';
std::cout << (cit > cit) << '\n';

// 元のイテレータとの比較
std::cout << (cit > se) << '\n';
std::cout << (se > cit) << '\n';
std::cout << (cit > cit.base()) << '\n';
}
```
* >[color ff0000]
### 出力
```
false
true
false
false
true
false
```

## バージョン
### 言語
- C++23

### 処理系
- [Clang](/implementation.md#clang): ??
- [GCC](/implementation.md#gcc): 13.1
- [Visual C++](/implementation.md#visual_cpp): 2022 Update 6

## 参照

- [P2278R4 `cbegin` should always return a constant iterator](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2278r4.html)
108 changes: 108 additions & 0 deletions reference/iterator/basic_const_iterator/op_greater_equal.md
@@ -0,0 +1,108 @@
# operator>=
* iterator[meta header]
* std[meta namespace]
* basic_const_iterator[meta class]
* function[meta id-type]
* cpp23[meta cpp]

```cpp
constexpr bool operator>=(const basic_const_iterator& y) const
requires random_access_iterator<Iterator>; // (1)

template<different-from<basic_const_iterator> I>
constexpr bool operator>=(const I& y) const
requires random_access_iterator<Iterator> && totally_ordered_with<Iterator, I>; // (2)

template<not-a-const-iterator I>
friend constexpr bool operator>=(const I& x, const basic_const_iterator& y)
requires random_access_iterator<Iterator> && totally_ordered_with<Iterator, I>; // (3) 非メンバ関数
```
* random_access_iterator[link /reference/iterator/random_access_iterator.md]
* totally_ordered_with[link /reference/concepts/totally_ordered.md]
* different-from[link /reference/ranges/different-from.md]

## 概要

`basic_const_iterator<Iterator>`オブジェクト同士あるいは別のイテレータとの間で、左辺が右辺以上かを判定する。

- (1) : 同じ`random_access_iterator`特殊化同士の間の`>=`比較
- (2) : `Iterator`と比較可能な型の値との間の`>=`比較
- (3) : (2)の逆順の演算子

## テンプレートパラメータ制約

`not-a-const-iterator<I>``I``basic_const_iterator`の特殊化ではない場合に`true`となる説明専用のコンセプトである。

## 効果

ラップしているイテレータを`current_`メンバ変数に保持するとして、以下と等価

- (1) : 以下と等価
```cpp
return current_ >= y.current_;
```

- (2) : 以下と等価
```cpp
return current_ >= y;
```

- (3) : 以下と等価
```cpp
return x >= y.current_;
```

## 備考

(3)の関数は[*Hidden friends*](/article/lib/hidden_friends.md)として定義される。

##
```cpp example
#include <iostream>
#include <iterator>
#include <vector>

int main() {
std::vector vec = {1, 2, 3, 4, 5};

std::basic_const_iterator cit = vec.begin();
auto se = vec.end();
std::basic_const_iterator cse = se;

std::cout << std::boolalpha;

// basic_const_iterator同士の比較
std::cout << (cit >= cse) << '\n';
std::cout << (cse >= cit) << '\n';
std::cout << (cit >= cit) << '\n';

// 元のイテレータとの比較
std::cout << (cit >= se) << '\n';
std::cout << (se >= cit) << '\n';
std::cout << (cit >= cit.base()) << '\n';
}
```
* >=[color ff0000]
### 出力
```
false
true
true
false
true
true
```

## バージョン
### 言語
- C++23

### 処理系
- [Clang](/implementation.md#clang): ??
- [GCC](/implementation.md#gcc): 13.1
- [Visual C++](/implementation.md#visual_cpp): 2022 Update 6

## 参照

- [P2278R4 `cbegin` should always return a constant iterator](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2278r4.html)
108 changes: 108 additions & 0 deletions reference/iterator/basic_const_iterator/op_less.md
@@ -0,0 +1,108 @@
# operator<
* iterator[meta header]
* std[meta namespace]
* basic_const_iterator[meta class]
* function[meta id-type]
* cpp23[meta cpp]

```cpp
constexpr bool operator<(const basic_const_iterator& y) const
requires random_access_iterator<Iterator>; // (1)

template<different-from<basic_const_iterator> I>
constexpr bool operator<(const I& y) const
requires random_access_iterator<Iterator> && totally_ordered_with<Iterator, I>; // (2)

template<not-a-const-iterator I>
friend constexpr bool operator<(const I& x, const basic_const_iterator& y)
requires random_access_iterator<Iterator> && totally_ordered_with<Iterator, I>; // (3) 非メンバ関数
```
* random_access_iterator[link /reference/iterator/random_access_iterator.md]
* totally_ordered_with[link /reference/concepts/totally_ordered.md]
* different-from[link /reference/ranges/different-from.md]

## 概要

`basic_const_iterator<Iterator>`オブジェクト同士あるいは別のイテレータとの間で、左辺が右辺より小さいかを判定する。

- (1) : 同じ`random_access_iterator`特殊化同士の間の`<`比較
- (2) : `Iterator`と比較可能な型の値との間の`<`比較
- (3) : (2)の逆順の演算子

## テンプレートパラメータ制約

`not-a-const-iterator<I>``I``basic_const_iterator`の特殊化ではない場合に`true`となる説明専用のコンセプトである。

## 効果

ラップしているイテレータを`current_`メンバ変数に保持するとして、以下と等価

- (1) : 以下と等価
```cpp
return current_ < y.current_;
```

- (2) : 以下と等価
```cpp
return current_ < y;
```

- (3) : 以下と等価
```cpp
return x < y.current_;
```

## 備考

(3)の関数は[*Hidden friends*](/article/lib/hidden_friends.md)として定義される。

##
```cpp example
#include <iostream>
#include <iterator>
#include <vector>

int main() {
std::vector vec = {1, 2, 3, 4, 5};

std::basic_const_iterator cit = vec.begin();
auto se = vec.end();
std::basic_const_iterator cse = se;

std::cout << std::boolalpha;

// basic_const_iterator同士の比較
std::cout << (cit < cse) << '\n';
std::cout << (cse < cit) << '\n';
std::cout << (cit < cit) << '\n';

// 元のイテレータとの比較
std::cout << (cit < se) << '\n';
std::cout << (se < cit) << '\n';
std::cout << (cit < cit.base()) << '\n';
}
```
* <[color ff0000]

### 出力
```
true
false
false
true
false
false
```

## バージョン
### 言語
- C++23

### 処理系
- [Clang](/implementation.md#clang): ??
- [GCC](/implementation.md#gcc): 13.1
- [Visual C++](/implementation.md#visual_cpp): 2022 Update 6

## 参照

- [P2278R4 `cbegin` should always return a constant iterator](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2278r4.html)

0 comments on commit 3f6f9ce

Please sign in to comment.