命名空间
变体
操作

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

来自 cppreference.cn
< cpp‎ | container‎ | mdspan
 
 
 
 
template< class... OtherIndexTypes >
constexpr reference operator[]( OtherIndexTypes... indices ) const;
(1) (since C++23)
template< class OtherIndexType >

constexpr reference operator[]

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

constexpr reference operator[]

    ( const std::array<OtherIndexType, rank()>& indices ) const;
(3) (since 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++ 标准。

DR 应用于 发布时的行为 正确的行为
LWG 3974 C++23 重载 (2,3) 未应用 extents_type::index-cast 应用

[编辑] 参见