Skip to content

Commit e37147a

Browse files
committed
mdspan: P3383R3対応 (#1504)
1 parent 038d6dc commit e37147a

File tree

5 files changed

+97
-4
lines changed

5 files changed

+97
-4
lines changed

lang/cpp26.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ C++26とは、2026年中に改訂される予定の、C++バージョンの通
143143
### コンテナ
144144
- [`std::vector<bool>::reference`](/reference/vector/vector.md)のプロキシ操作として、`const`修飾付きの代入と`swap()`メンバ関数を追加
145145
- [`std::mdspan`](/reference/mdspan/mdspan.md)から部分ビューを取り出す[`std::submdspan()`](/reference/mdspan/submdspan.md)を追加
146-
- [`std::mdspan`](/reference/mdspan/mdspan.md)に、インデックスを指定して要素を取り出す[`at()`](/reference/mdspan/mdspan/at.md.nolink)メンバ関数を追加
146+
- [`std::mdspan`](/reference/mdspan/mdspan.md)に、インデックスを指定して要素を取り出す[`at()`](/reference/mdspan/mdspan/at.md)メンバ関数を追加
147147
- [`std::mdspan`](/reference/mdspan/mdspan.md)に対する[`std::dextents`](/reference/mdspan/extents.md)指定の冗長さを解決する[`std::dims`](/reference/mdspan/extents.md)を追加
148148
- [`std::mdspan`](/reference/mdspan/mdspan.md)のレイアウトとして、[`std::layout_left_padded`](/reference/mdspan/layout_left_padded.md)[`std::layout_right_padded`](/reference/mdspan/layout_right_padded.md)を追加
149149
- [`<mdspan>`](/reference/mdspan.md)に、要素アクセスにアライメント保証を与える[`std::aligned_accessor`](/reference/mdspan/aligned_accessor.md)を追加

lang/cpp26/feature_test_macros.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@
145145
|`__cpp_lib_simd_complex`|`202502L`|[`<simd>`](/reference/simd.md.nolink)[`std::complex`](/reference/complex/complex.md)をサポートする|[`<simd>`](/reference/simd.md.nolink)|
146146
|`__cpp_lib_simd_permutations`|`202506L`|[`<simd>`](/reference/simd.md.nolink)`permute()`などを追加する|[`<simd>`](/reference/simd.md.nolink)|
147147
|`__cpp_lib_smart_ptr_owner_equality`|`202306L`|[`<memory>`](/reference/memory.md)[`std::owner_hash`](/reference/memory/owner_hash.md.nolink)[`std::owner_equal`](/reference/memory/owner_equal.md.nolink)を追加|[`<memory>`](/reference/memory.md)|
148-
|`__cpp_lib_span`|`202311L`|[`std::mdspan`](/reference/mdspan/mdspan.md)[`at()`](/reference/mdspan/mdspan/at.md.nolink)メンバ関数を追加|[`<span>`](/reference/span.md)|
148+
|`__cpp_lib_span`|`202311L`|[`std::mdspan`](/reference/mdspan/mdspan.md)[`at()`](/reference/mdspan/mdspan/at.md)メンバ関数を追加|[`<span>`](/reference/span.md)|
149149
|`__cpp_lib_span_initializer_list`|`202311L`|[`std::span`](/reference/span/span.md)[`std::initializer_list`](/reference/initializer_list/initializer_list.md)をとるコンストラクタを追加|[`<span>`](/reference/span.md)|
150150
|`__cpp_lib_sstream_from_string_view`|`202306L`|[`std::basic_stringstream`](/reference/sstream/basic_stringstream.md)などが[`std::basic_string_view`](/reference/string_view/basic_string_view.md)から構築可能に|[`<sstream>`](/reference/sstream.md)|
151151
|`__cpp_lib_string_subview`|`202506L`|[`std::basic_string`](/reference/string/basic_string.md)[`std::basic_string_view`](/reference/string_view/basic_string_view.md)`subview()`を追加|[`<string>`](/reference/string.md), [`<string_view>`](/reference/string_view.md)|

reference/mdspan/mdspan.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ namespace std {
7272
| 名前 | 説明 | 対応バージョン |
7373
|------|------|----------------|
7474
| [`operator[]`](mdspan/op_at.md) | 多次元配列の要素アクセス | C++23 |
75+
| [`at`](mdspan/at.md) | 多次元配列の要素アクセス | C++26 |
7576
7677
### 多次元配列サイズ
7778
@@ -189,3 +190,5 @@ int main()
189190
- [P2599R2 `index_type` & `size_type` in `mdspan`](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2599r2.pdf)
190191
- [P2604R0 `mdspan`: rename `pointer` and `contiguous`](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2604r0.html)
191192
- [P2613R1 Add the missing `empty` to `mdspan`](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2613r1.html)
193+
- [P3383R3 mdspan.at()](https://open-std.org/jtc1/sc22/wg21/docs/papers/2025/p3383r3.html)
194+
- C++26で`at`メンバ関数を追加

reference/mdspan/mdspan/at.md

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# at
2+
* mdspan[meta header]
3+
* function template[meta id-type]
4+
* std[meta namespace]
5+
* mdspan[meta class]
6+
* cpp26[meta cpp]
7+
8+
```cpp
9+
template<class... OtherIndexTypes>
10+
constexpr reference at(OtherIndexTypes... indices) const; // (1)
11+
12+
template<class OtherIndexType>
13+
constexpr reference at(span<OtherIndexType, rank()> indices) const; // (2)
14+
15+
template<class OtherIndexType>
16+
constexpr reference at(const array<OtherIndexType, rank()>& indices) const; // (3)
17+
```
18+
* rank()[link rank.md]
19+
* span[link /reference/span/span.md]
20+
* array[link /reference/array/array.md]
21+
22+
## 概要
23+
多次元インデクスを用いて要素にアクセスする。
24+
25+
26+
## テンプレートパラメータ制約
27+
- (1) :
28+
- `(`[`is_convertible_v`](/reference/type_traits/is_convertible.md)`<OtherIndexTypes, index_type> && ...)`が`true`、かつ
29+
- `(`[`is_nothrow_constructible_v`](/reference/type_traits/is_nothrow_constructible.md)`<index_type, OtherIndexTypes> && ...)`が`true`、かつ
30+
- `sizeof...(OtherIndexTypes) ==` [`rank()`](rank.md)が`true`であること
31+
- (2), (3) :
32+
- [`is_convertible_v`](/reference/type_traits/is_convertible.md)`<const OtherIndexTypes&, index_type>`が`true`、かつ
33+
- [`is_nothrow_constructible_v`](/reference/type_traits/is_nothrow_constructible.md)`<index_type, const OtherIndexTypes&>`が`true`であること
34+
35+
36+
## 効果
37+
(1) : 説明用のパック`I`を[`extents_type::index_cast`](../extents/index-cast.md)`(std::move(indices))`として、[`(*this)[I...]`](op_at.md)を返す。
38+
39+
(2), (3) : 説明用のパラメータパック`P`が[`is_same_v`](/reference/type_traits/is_same.md)`<`[`make_index_sequence`](/reference/utility/make_index_sequence.md)`<`[`rank()`](rank.md)`>,` [`index_sequence`](/reference/utility/index_sequence.md)`<P...>> == true`となるとき、以下と等価
40+
41+
```cpp
42+
return at(extents_type::index-cast(as_const(indices[P]))...);
43+
```
44+
* extents_type::index-cast[link ../extents/index-cast.md]
45+
* as_const[link /reference/utility/as_const.md]
46+
47+
48+
## 例外
49+
(1) : 説明用のパック`I`を[`extents_type::index_cast`](../extents/index-cast.md)`(std::move(indices))`として、`I`が`extents()`の多次元インデクス値でなければ[`out_of_range`](/reference/stdexcept/out_of_range.md)を送出する。
50+
51+
52+
## 例
53+
```cpp example
54+
#include <cassert>
55+
#include <mdspan>
56+
57+
int main()
58+
{
59+
int arr[] = {1, 2, 3, 4, 5, 6};
60+
// 静的要素数 2x3 の2次元配列ビュー
61+
std::mdspan<int, std::extents<size_t, 2, 3>> mat{arr};
62+
63+
assert(mat.at(0, 0) == 1);
64+
assert(mat.at(1, 2) == 6);
65+
}
66+
```
67+
68+
### 出力
69+
```
70+
```
71+
72+
73+
## バージョン
74+
### 言語
75+
- C++26
76+
77+
### 処理系
78+
- [Clang](/implementation.md#clang): ??
79+
- [GCC](/implementation.md#gcc): ??
80+
- [ICC](/implementation.md#icc): ??
81+
- [Visual C++](/implementation.md#visual_cpp): ??
82+
83+
84+
## 関連項目
85+
- [`operator[]`](op_at.md)
86+
87+
88+
## 参照
89+
- [P3383R3 mdspan.at()](https://open-std.org/jtc1/sc22/wg21/docs/papers/2025/p3383r3.html)

reference/mdspan/mdspan/op_at.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ int main()
6767
// 静的要素数 2x3 の2次元配列ビュー
6868
std::mdspan<int, std::extents<size_t, 2, 3>> mat{arr};
6969

70-
assert(map[0,0] == 1);
71-
assert(map[1,2] == 6);
70+
assert(mat[0,0] == 1);
71+
assert(mat[1,2] == 6);
7272
}
7373
```
7474

@@ -90,6 +90,7 @@ int main()
9090

9191
## 関連項目
9292
- C++23 [添字演算子の多次元サポート](/lang/cpp23/multidimensional_subscript_operator.md)
93+
- [`at`](at.md)
9394

9495

9596
## 参照

0 commit comments

Comments
 (0)