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

来自cppreference.com
< cpp‎ | container‎ | 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[]

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

返回 mdspan 的第 indices 个元素的引用。

1) 等价于 return acc_ .access(ptr_, map_ (static_cast<index_type>(std::move(indices))...));
此重载只有在以下所有值都是 true 时才会参与重载决议:

如果extents_type::index-cast (std::move(indices)) 不是 extents() 中的多维索引,那么行为未定义。

(C++26 前)

如果extents_type::index-cast (std::move(indices)) 不是 extents() 中的多维索引,那么:

  • 如果实现是硬化实现,那么就会发生契约违背。并且契约违背处理函数在“观察”求值语义下返回时行为未定义。
  • 如果实现不是硬化实现,那么行为未定义。
(C++26 起)
2,3)P 为使得 std::is_same_v<std::make_index_sequence<rank()>,
               std::index_sequence<P...>>
true 的形参包,等价于 return operator[](extents_type::index-cast (std::as_const(indices[P]))...);
此重载只有在以下所有值都是 true 时才会参与重载决议:

目录

[编辑]参数

indices - 要访问的元素的索引

[编辑]返回值

元素的引用。

[编辑]示例

[编辑]缺陷报告

下列更改行为的缺陷报告追溯地应用于以前出版的 C++ 标准。

缺陷报告 应用于 出版时的行为 正确行为
LWG 3974 C++23 重载 (2,3) 没有应用 extents_type::index-cast 会应用

[编辑]参阅

close