命名空间
变体
操作

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

来自 cppreference.cn
< 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 已应用

[编辑] 参阅