Skip to content

Commit c422171

Browse files
committed
C++26対応として、span::atを追加 (close #1235)
1 parent 7df12cd commit c422171

File tree

4 files changed

+78
-1
lines changed

4 files changed

+78
-1
lines changed

lang/cpp26.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ C++26とは、2026年中に改訂される予定の、C++バージョンの通
6666
- [`std::mdspan`](/reference/mdspan/mdspan.md)のサブ配列版として[`std::submdspan`](/reference/mdspan/submdspan.md.nolink)を追加
6767
- [`std::span`](/reference/span/span.md)に、以下を追加
6868
- [`std::initializer_list`](/reference/initializer_list/initializer_list.md)をとるコンストラクタ
69-
- インデックスアクセスのための[`at()`](/reference/span/span/at.md.nolink)メンバ関数
69+
- インデックスアクセスのための[`at()`](/reference/span/span/at.md)メンバ関数
7070
- 連想コンテナの以下のメンバ関数に、一時オブジェクトが生成されるコストを抑える拡張を追加
7171
- [`std::map`](/reference/map/map.md)
7272
- [`operator[]`](/reference/map/map/op_at.md)

reference/span/span.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ namespace std {
9393
| 名前 | 説明 | 対応バージョン |
9494
|------|------|----------------|
9595
| [`operator[]`](span/op_at.md) | 参照範囲から、任意の位置の要素を取得する | C++20 |
96+
| [`at`](span/at.md) | 参照範囲から、任意の位置の要素を取得する | C++26 |
9697
| [`front`](span/front.md) | 参照範囲の先頭要素を取得する | C++20 |
9798
| [`back`](span/back.md) | 参照範囲の末尾要素を取得する | C++20 |
9899
| [`data`](span/data.md) | 参照範囲の先頭を指すポインタを取得する | C++20 |

reference/span/span/at.md

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# at
2+
* span[meta header]
3+
* std[meta namespace]
4+
* span[meta class]
5+
* function[meta id-type]
6+
* cpp26[meta cpp]
7+
8+
```cpp
9+
constexpr reference at(size_type i) const;
10+
```
11+
12+
## 概要
13+
参照範囲から、任意の位置の要素を取得する。
14+
15+
16+
## 戻り値
17+
以下と等価:
18+
19+
```cpp
20+
return *(data() + i);
21+
```
22+
* data()[link data.md]
23+
24+
25+
## 計算量
26+
定数時間
27+
28+
29+
## 例外
30+
`i >=` [`size()`](size.md)の場合、[`out_of_range`](/reference/stdexcept.md)例外を送出する。
31+
32+
33+
##
34+
```cpp example
35+
#include <cassert>
36+
#include <span>
37+
#include <vector>
38+
39+
int main()
40+
{
41+
std::vector<int> v = {1, 2, 3, 4, 5};
42+
43+
int& x = std::span{v}.at(2);
44+
assert(x == 3);
45+
46+
int& y = std::span{v}.subspan(2, 3).at(1);
47+
assert(y == 4);
48+
}
49+
```
50+
* at[color ff0000]
51+
* subspan[link subspan.md]
52+
53+
### 出力
54+
```
55+
```
56+
57+
## バージョン
58+
### 言語
59+
- C++26
60+
61+
### 処理系
62+
- [Clang](/implementation.md#clang): ??
63+
- [GCC](/implementation.md#gcc): 14
64+
- [Visual C++](/implementation.md#visual_cpp): ??
65+
66+
67+
## 関連項目
68+
- [`operator[]`](op_at.md)
69+
70+
71+
## 参照
72+
- [P2821R5 `span.at()`](https://open-std.org/jtc1/sc22/wg21/docs/papers/2023/p2821r5.html)

reference/span/span/op_at.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,5 +65,9 @@ int main()
6565
- [Visual C++](/implementation.md#visual_cpp): ??
6666

6767

68+
## 関連項目
69+
- [`at`](at.md)
70+
71+
6872
## 参照
6973
- [P1872R0 `span` should have `size_type`, not `index_type`](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1872r0.pdf)

0 commit comments

Comments
 (0)