Skip to content

Commit 02ed11e

Browse files
committed
basic_const_iterator : iter_move追加 #1084
1 parent 3f6f9ce commit 02ed11e

File tree

2 files changed

+86
-1
lines changed

2 files changed

+86
-1
lines changed

reference/iterator/basic_const_iterator.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ namespace std {
7272
| [`operator+`](basic_const_iterator/op_plus.md) | イテレータを進める | C++23 |
7373
| [`operator-`](basic_const_iterator/op_unary_minus.md) | イテレータを逆に進める | C++23 |
7474
| [`operator-`](basic_const_iterator/op_minus.md) | 2つの`basic_const_iterator`の差を求める | C++23 |
75-
| [`iter_move`](basic_const_iterator/iter_move.md.nolink) | イテレータの要素の移動 | C++23 |
75+
| [`iter_move`](basic_const_iterator/iter_move.md) | イテレータの要素の移動 | C++23 |
7676
7777
## 非メンバ関数
7878
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# iter_move (非メンバ関数)
2+
* iterator[meta header]
3+
* std[meta namespace]
4+
* basic_const_iterator[meta class]
5+
* function[meta id-type]
6+
* cpp23[meta cpp]
7+
8+
```cpp
9+
friend constexpr rvalue-reference iter_move(const basic_const_iterator& i) noexcept(/*see below*/);
10+
```
11+
12+
## 概要
13+
14+
`basic_const_iterator`である`i`の指す要素をムーブする。
15+
16+
戻り値の`rvalue-reference`は次のように求められる`const`かつ右辺値となる型である
17+
18+
```cpp
19+
using rvalue-reference = common_reference_t<const iter_value_t<Iterator>&&, iter_rvalue_reference_t<Iterator>>;
20+
```
21+
22+
## 戻り値
23+
24+
ラップしているイテレータを`current_`メンバ変数に保持するとして、次のようになる
25+
26+
```cpp
27+
return static_cast<rvalue-reference>(ranges::iter_move(i.current_));
28+
```
29+
* ranges::iter_move[link /reference/iterator/iter_move.md]
30+
31+
## 例外
32+
33+
`noexcept`指定には次の式が指定される
34+
35+
```cpp
36+
noexcept(static_cast<rvalue-reference>(ranges::iter_move(i.current_)))
37+
```
38+
39+
## 備考
40+
41+
この関数は[*Hidden friends*](/article/lib/hidden_friends.md)として定義される。
42+
43+
## 例
44+
```cpp example
45+
#include <iterator>
46+
#include <vector>
47+
#include <iostream>
48+
49+
int main() {
50+
std::vector vec = {1, 2, 3, 4, 5};
51+
52+
std::basic_const_iterator cit = vec.begin();
53+
54+
// ADLによる呼び出し
55+
int n1 = iter_move(cit);
56+
std::cout << n1 << std::endl;
57+
58+
++cit;
59+
60+
// ranges::iter_move CPOによる呼び出し
61+
int n2 = std::ranges::iter_move(cit);
62+
std::cout << n2 << std::endl;
63+
}
64+
```
65+
* iter_move[color ff0000]
66+
* ranges::iter_move[link /reference/iterator/iter_move.md]
67+
68+
### 出力
69+
```
70+
1
71+
2
72+
```
73+
74+
## バージョン
75+
### 言語
76+
- C++23
77+
78+
### 処理系
79+
- [Clang](/implementation.md#clang): ??
80+
- [GCC](/implementation.md#gcc): 13.1
81+
- [Visual C++](/implementation.md#visual_cpp): 2022 Update 6
82+
83+
## 参照
84+
85+
- [P2278R4 `cbegin` should always return a constant iterator](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2278r4.html)

0 commit comments

Comments
 (0)