Namespaces
Variants

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

From cppreference.net
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 第 indices th 个元素的引用。

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++标准。

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

参见