<tbody>
</tbody>
| 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 个元素的引用。
1) 等价于
return acc_ .access(ptr_, map_ (static_cast<index_type>(std::move(indices))...));。
此重载只有在以下所有值都是
true 时才会参与重载决议:
(std::is_convertible_v<OtherIndexTypes, index_type> && ...)
(std::is_nothrow_constructible_v<index_type, OtherIndexTypes> && ...)
sizeof...(OtherIndexTypes) == rank()
|
如果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 时才会参与重载决议:
std::is_convertible_v<const OtherIndexType&, index_type>
std::is_nothrow_constructible_v<index_type, const OtherIndexType&>
参数
返回值
元素的引用。
示例
缺陷报告
下列更改行为的缺陷报告追溯地应用于以前出版的 C++ 标准。
| 缺陷报告
|
应用于
|
出版时的行为
|
正确行为
|
| LWG 3974
|
C++23
|
重载 (2,3) 没有应用 extents_type::index-cast
|
会应用
|
参阅