|
| 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) |
0 commit comments