最終更新日時(UTC): 2026年01月21日 13時43分46秒
yoh が更新

履歴 編集

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) : 説明用のパックIextents_type::index_cast(std::move(indices))として、(*this)[I...]を返す。

(2), (3) : 説明用のパラメータパックPis_same_v<make_index_sequence<rank()>, index_sequence<P...>> == trueとなるとき、以下と等価

return at(extents_type::index-cast(as_const(indices[P]))...);

例外

(1) : 説明用のパックIextents_type::index_cast(std::move(indices))として、Iextents()の多次元インデクス値でなければ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

処理系

関連項目

参照

Morty Proxy This is a proxified and sanitized view of the page, visit original site.