function template
<mdspan>
std::mdspan::at(C++26)
template<class... OtherIndexTypes>
constexpr reference at(OtherIndexTypes... indices) const; // (1)
template<class OtherIndexType>
constexpr reference at(span<OtherIndexType, rank()> indices) const; // (2)
template<class OtherIndexType>
constexpr reference at(const array<OtherIndexType, rank()>& indices) const; // (3)
概要
多次元インデクスを用いて要素にアクセスする。
テンプレートパラメータ制約
- (1) :
(is_convertible_v<OtherIndexTypes, index_type> && ...)がtrue、かつ(is_nothrow_constructible_v<index_type, OtherIndexTypes> && ...)がtrue、かつsizeof...(OtherIndexTypes) == rank()がtrueであること
- (2), (3) :
is_convertible_v<const OtherIndexTypes&, index_type>がtrue、かつis_nothrow_constructible_v<index_type, const OtherIndexTypes&>がtrueであること
効果
(1) : 説明用のパックIをextents_type::index_cast(std::move(indices))として、(*this)[I...]を返す。
(2), (3) : 説明用のパラメータパックPがis_same_v<make_index_sequence<rank()>, index_sequence<P...>> == trueとなるとき、以下と等価
return at(extents_type::index-cast(as_const(indices[P]))...);
例外
(1) : 説明用のパックIをextents_type::index_cast(std::move(indices))として、Iがextents()の多次元インデクス値でなければout_of_rangeを送出する。
例
#include <cassert>
#include <mdspan>
int main()
{
int arr[] = {1, 2, 3, 4, 5, 6};
// 静的要素数 2x3 の2次元配列ビュー
std::mdspan<int, std::extents<size_t, 2, 3>> mat{arr};
assert(mat.at(0, 0) == 1);
assert(mat.at(1, 2) == 6);
}
出力
バージョン
言語
- C++26
処理系
- Clang: ??
- GCC: ??
- ICC: ??
- Visual C++: ??