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
3 changed files
with
135 additions
and
2 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,74 @@ | ||
# operator-> | ||
* iterator[meta header] | ||
* std[meta namespace] | ||
* basic_const_iterator[meta class] | ||
* function[meta id-type] | ||
* cpp23[meta cpp] | ||
|
||
```cpp | ||
constexpr const auto* operator->() const | ||
requires is_lvalue_reference_v<iter_reference_t<Iterator>> && | ||
same_as<remove_cvref_t<iter_reference_t<Iterator>>, value_type>; | ||
``` | ||
* is_lvalue_reference_v[link /reference/type_traits/is_lvalue_reference.md] | ||
* iter_reference_t[link /reference/iterator/iter_reference_t.md] | ||
* same_as[link /reference/concepts/same_as.md] | ||
* remove_cvref_t[link /reference/type_traits/remove_cvref.md] | ||
|
||
## 概要 | ||
|
||
イテレータを通して参照先の要素のメンバにアクセスする | ||
|
||
## 戻り値 | ||
|
||
ラップするイテレータを`current_`というメンバに保持するとして | ||
|
||
- `Iterator`が[`contiguous_iterator`](/reference/iterator/contiguous_iterator.md)のモデルとなる場合 | ||
- [`to_address`](/reference/memory/to_address.md)`((current_))` | ||
- それ以外の場合 | ||
- [`addressof`](/reference/memory/addressof.md)`(*current_)` | ||
|
||
## 例 | ||
```cpp example | ||
#include <iostream> | ||
#include <iterator> | ||
#include <vector> | ||
|
||
struct S { | ||
int n; | ||
|
||
void print() const { | ||
std::cout << "call const : " << this->n << '\n'; | ||
} | ||
|
||
void print() { | ||
std::cout << "call non const : " << this->n << '\n'; | ||
} | ||
}; | ||
|
||
int main() { | ||
std::vector<S> vec = {S{1}, S{3}}; | ||
|
||
std::basic_const_iterator cit = vec.begin(); | ||
|
||
cit->print(); | ||
} | ||
``` | ||
* cit->[color ff0000] | ||
### 出力 | ||
``` | ||
call const : 1 | ||
``` | ||
## バージョン | ||
### 言語 | ||
- C++20 | ||
### 処理系 | ||
- [Clang](/implementation.md#clang): ?? | ||
- [GCC](/implementation.md#gcc): 10.1 | ||
- [Visual C++](/implementation.md#visual_cpp): 2019 Update 9 | ||
## 参照 | ||
- [P0896R4 The One Ranges Proposal (was Merging the Ranges TS)](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0896r4.pdf) |
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,59 @@ | ||
# operator* | ||
* iterator[meta header] | ||
* std[meta namespace] | ||
* basic_const_iterator[meta class] | ||
* function[meta id-type] | ||
* cpp23[meta cpp] | ||
|
||
```cpp | ||
constexpr reference operator*() const; | ||
``` | ||
|
||
## 概要 | ||
イテレータを間接参照する。 | ||
|
||
戻り値型`reference`は、[`iter_const_reference_t`](/reference/iterator/iter_const_reference_t.md)`<Iterator>`のエイリアス。 | ||
|
||
## 効果 | ||
|
||
ラップしているイテレータを`current_`メンバ変数に保持するとして、以下と等価 | ||
|
||
`return static_cast<reference>(*current_);` | ||
|
||
## 例 | ||
```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(); | ||
|
||
std::cout << *cit << '\n'; | ||
|
||
// 要素を変更できない | ||
//*cit = 0; | ||
} | ||
``` | ||
* *cit[color ff0000] | ||
|
||
### 出力 | ||
``` | ||
1 | ||
``` | ||
|
||
## バージョン | ||
### 言語 | ||
- 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) |