Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
basic_const_iterator : ++ -- += -= 追加 #1084
- Loading branch information
Showing
5 changed files
with
288 additions
and
4 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
# operator-- | ||
* iterator[meta header] | ||
* std[meta namespace] | ||
* basic_const_iterator[meta class] | ||
* function[meta id-type] | ||
* cpp23[meta cpp] | ||
|
||
```cpp | ||
constexpr basic_const_iterator& operator--() requires bidirectional_iterator<Iterator>; // (1) | ||
|
||
constexpr basic_const_iterator operator--(int) requires bidirectional_iterator<Iterator>; // (2) | ||
``` | ||
* bidirectional_iterator[link ./bidirectional_iterator.md] | ||
|
||
## 概要 | ||
|
||
イテレータをデクリメントする。 | ||
|
||
- (1) : 前置デクリメント | ||
- (2) : 後置デクリメント | ||
|
||
## 効果 | ||
|
||
ラップするイテレータを`current_`というメンバに保持するとして | ||
|
||
- (1) : 以下と等価 | ||
```cpp | ||
--current_; | ||
return *this; | ||
``` | ||
- (2) : 以下と等価 | ||
```cpp | ||
auto tmp = *this; | ||
--*this; | ||
return tmp; | ||
``` | ||
|
||
## 例 | ||
```cpp example | ||
#include <iostream> | ||
#include <iterator> | ||
|
||
int main() { | ||
std::vector vec = {1, 2, 3, 4, 5}; | ||
|
||
std::basic_const_iterator cit = vec.end(); | ||
|
||
--cit; | ||
|
||
std::cout << *cit << '\n'; | ||
|
||
cit--; | ||
|
||
std::cout << *cit << '\n'; | ||
|
||
} | ||
``` | ||
* --ci[color ff0000] | ||
* ci--[color ff0000] | ||
|
||
### 出力 | ||
``` | ||
5 | ||
4 | ||
``` | ||
|
||
## バージョン | ||
### 言語 | ||
- 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) |
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,79 @@ | ||
# operator++ | ||
* iterator[meta header] | ||
* std[meta namespace] | ||
* basic_const_iterator[meta class] | ||
* function[meta id-type] | ||
* cpp23[meta cpp] | ||
|
||
```cpp | ||
constexpr basic_const_iterator& operator++(); // (1) | ||
|
||
constexpr void operator++(int); // (2) | ||
constexpr basic_const_iterator operator++(int) requires forward_iterator<Iterator>; // (3) | ||
``` | ||
* forward_iterator[link ./forward_iterator.md] | ||
|
||
## 概要 | ||
|
||
イテレータをインクリメントする。 | ||
|
||
- (1) : 前置デクリメント | ||
- (2)(3) : 後置デクリメント | ||
|
||
## 効果 | ||
|
||
ラップするイテレータを`current_`というメンバに保持するとして | ||
|
||
- (1) : 以下と等価 | ||
```cpp | ||
++current_; | ||
return *this; | ||
``` | ||
- (2) : `++current_;` | ||
- (3) : 以下と等価 | ||
```cpp | ||
auto tmp = *this; | ||
++*this; | ||
return tmp; | ||
``` | ||
|
||
## 例 | ||
```cpp example | ||
#include <iostream> | ||
#include <iterator> | ||
|
||
int main() { | ||
std::vector vec = {1, 2, 3, 4, 5}; | ||
|
||
std::basic_const_iterator cit = vec.begin(); | ||
|
||
++cit; | ||
|
||
std::cout << *cit << '\n'; | ||
|
||
cit++; | ||
|
||
std::cout << *cit << '\n'; | ||
} | ||
``` | ||
* ++cit[color ff0000] | ||
* cit++[color ff0000] | ||
|
||
### 出力 | ||
``` | ||
2 | ||
3 | ||
``` | ||
|
||
## バージョン | ||
### 言語 | ||
- 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) |
63 changes: 63 additions & 0 deletions
63
reference/iterator/basic_const_iterator/op_minus_assign.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,63 @@ | ||
# operator-= | ||
* iterator[meta header] | ||
* std[meta namespace] | ||
* basic_const_iterator[meta class] | ||
* function[meta id-type] | ||
* cpp23[meta cpp] | ||
|
||
```cpp | ||
constexpr basic_const_iterator& operator-=(difference_type n) | ||
requires random_access_iterator<Iterator>; | ||
``` | ||
* random_access_iterator[link /reference/iterator/random_access_iterator.md] | ||
|
||
## 概要 | ||
|
||
イテレータを`n`回逆に進める。 | ||
|
||
## 効果 | ||
|
||
ラップするイテレータを`current_`というメンバに保持するとして、 以下と等価 | ||
|
||
```cpp | ||
current -= n; | ||
return *this; | ||
``` | ||
|
||
## 戻り値 | ||
|
||
`*this` | ||
|
||
## 例 | ||
```cpp example | ||
#include <iostream> | ||
#include <iterator> | ||
|
||
int main() { | ||
std::vector vec = {1, 2, 3, 4, 5}; | ||
|
||
std::basic_const_iterator cit = vec.end(); | ||
|
||
cit -= 2; | ||
|
||
std::cout << *cit << '\n'; | ||
} | ||
``` | ||
|
||
### 出力 | ||
``` | ||
4 | ||
``` | ||
|
||
## バージョン | ||
### 言語 | ||
- 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) |
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,64 @@ | ||
# operator+= | ||
* iterator[meta header] | ||
* std[meta namespace] | ||
* basic_const_iterator[meta class] | ||
* function[meta id-type] | ||
* cpp23[meta cpp] | ||
|
||
```cpp | ||
constexpr basic_const_iterator& operator+=(difference_type n) | ||
requires random_access_iterator<Iterator>; | ||
``` | ||
* random_access_iterator[link /reference/iterator/random_access_iterator.md] | ||
|
||
|
||
## 概要 | ||
|
||
イテレータを`n`回進める。 | ||
|
||
## 事前条件 | ||
|
||
現在のカウントの値を`length`メンバ変数に保持するとして、`n <= length` | ||
|
||
## 効果 | ||
|
||
ラップするイテレータを`current_`というメンバに保持するとして、 以下と等価 | ||
|
||
```cpp | ||
current += n; | ||
return *this; | ||
``` | ||
|
||
## 例 | ||
```cpp example | ||
#include <iostream> | ||
#include <iterator> | ||
|
||
int main() { | ||
std::vector vec = {1, 2, 3, 4, 5}; | ||
|
||
std::basic_const_iterator cit = vec.begin(); | ||
|
||
cit += 2; | ||
|
||
std::cout << *cit << '\n'; | ||
} | ||
``` | ||
|
||
### 出力 | ||
``` | ||
3 | ||
``` | ||
|
||
## バージョン | ||
### 言語 | ||
- 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) |