名稱空間
變體
操作

std::mdspan<T,Extents,LayoutPolicy,AccessorPolicy>::operator[]

來自 cppreference.com
< cpp‎ | 容器‎ | mdspan
 
 
 
 
template< class... OtherIndexTypes >
constexpr reference operator[]( OtherIndexTypes... indices ) const;
(1) (C++23 起)
template< class OtherIndexType >

constexpr reference operator[]

    ( std::span<OtherIndexType, rank()> indices ) const;
(2) (C++23 起)
template< class OtherIndexType >

constexpr reference operator[]

    ( const std::array<OtherIndexType, rank()>& indices ) const;
(3) (C++23 起)

返回 mdspan 的 indicesth 元素的引用。

1) 等價於 return acc_.access(ptr_, map_(static_cast<index_type>(std::move(indices))...));
僅當以下條件成立時,此過載才參與過載決議:
Iextents_type::index-cast(std::move(indices))。若 I 不是 extents() 中的多維索引,即 map_(I) < map_.required_span_size()false,則行為未定義。
2,3)P 是一個引數包,使得 std::is_same_v<make_index_sequence<rank()>, index_sequence<P...>>true,則運算子等價於 return operator[](extents_type::index-cast(std::as_const(indices[P]))...);
僅當以下條件成立時,此過載才參與過載決議:

目錄

[編輯] 引數

indices - 要訪問元素的索引

[編輯] 返回值

元素的引用。

[編輯] 示例

[編輯] 缺陷報告

下列更改行為的缺陷報告追溯地應用於以前出版的 C++ 標準。

缺陷報告 應用於 釋出時的行為 正確的行為
LWG 3974 C++23 過載 (2,3) 未應用 extents_type::index-cast 已應用

[編輯] 參閱