Skip to content

Commit

Permalink
P2259R1対応 counted_iterator::operator->追加
Browse files Browse the repository at this point in the history
  • Loading branch information
onihusube committed Sep 27, 2023
1 parent 1cededd commit 8974dd3
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 1 deletion.
2 changes: 1 addition & 1 deletion reference/iterator/counted_iterator.md
Expand Up @@ -49,7 +49,7 @@ namespace std {
| [`base`](counted_iterator/base.md) | 元のイテレータを取得する | C++20 |
| [`count`](counted_iterator/count.md) | 代入演算子 | C++20 |
| [`operator*`](counted_iterator/op_deref.md) | 間接参照演算子 | C++20 |
| [`operator->`](counted_iterator/op_arrow.md.nolink) | メンバアクセス演算子 | C++20 |
| [`operator->`](counted_iterator/op_arrow.md) | メンバアクセス演算子 | C++20 |
| [`operator++`](counted_iterator/op_increment.md) | イテレータをインクリメントする | C++20 |
| [`operator--`](counted_iterator/op_decrement.md) | イテレータをデクリメントする | C++20 |
| [`operator+`](counted_iterator/op_plus.md) | イテレータを進める | C++20 |
Expand Down
74 changes: 74 additions & 0 deletions reference/iterator/counted_iterator/op_arrow.md
@@ -0,0 +1,74 @@
# operator->
* iterator[meta header]
* std[meta namespace]
* counted_iterator[meta class]
* function[meta id-type]
* cpp20[meta cpp]

```cpp
constexpr auto operator->() const noexcept
requires contiguous_iterator<I>;
```
* contiguous_iterator[link /reference/iterator/contiguous_iterator.md]

## 概要
イテレータを通して参照先の要素のメンバにアクセスする

## 効果

`I`の値を`current`メンバ変数に保持するとして、以下と等価

```cpp
return to_address(current);
```
* to_address[link /reference/memory/to_address.md]

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

struct S {
int n;

S(int a) : n{a} {}

void print() const {
std::cout << this->n << '\n';
}
};

int main() {
std::vector<S> vec = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};

std::counted_iterator ci{std::ranges::begin(vec), 5};

ci->print();

++ci;

ci->print();
}
```
* ci->[color ff0000]
* ranges::begin[link /reference/ranges/begin.md]
### 出力
```
1
2
```
## バージョン
### 言語
- C++20
### 処理系
- [Clang](/implementation.md#clang): ??
- [GCC](/implementation.md#gcc): 12.0
- [Visual C++](/implementation.md#visual_cpp): 2022
## 参照
- [P2259R1 Repairing input range adaptors and `counted_iterator`](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p2259r1.html)

0 comments on commit 8974dd3

Please sign in to comment.