std::mdspan::operator[](3)
π std::mdspan::operator[](3) π
okay so this is the std::mdspan::operator[] page, bestie, and itβs from the C++ Standard Libary manual (yes, thatβs the manual name as written here, no cap π«Ά). Page (3) energy. Letβs get into it.
πΈ NAME πΈ
std::mdspan::operator[] β literally std::mdspan::operator[]. Iconic, no notes.
β¨ Synopsis β¨
Three overloads, all (since C++23), all const, all returning reference. Hereβs the exact lineup:
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)
Returns a reference to the indices^th element of the mdspan.
- Equivalent to:
return acc_.access(ptr_, map_(static_cast<index_type>(std::move(indices))...));
This overload participates in overload resolution only if:
(std::is_convertible_v<OtherIndexTypes, index_type> && ...)istrue,(std::is_nothrow_constructible_v<index_type, OtherIndexTypes> && ...)istrue, andsizeof...(OtherIndexTypes) == rank()istrue.
Let I be extents_type::index-cast(std::move(indices)). Then the behavior is undefined if I is not a multidimensional index in extents(), i.e., map_(I) < map_.required_span_size() is false.
β οΈ bestie, undefined behavior is not a vibe. If that condition is false, you are off the map. π
2,3) Let P be a parameter pack such that std::is_same_v<make_index_sequence<rank()>, index_sequence<P...>> is true, then the operator is equivalent to:
return operator[](extents_type::index-cast(std::as_const(indices[P]))...);
This overload participates in overload resolution only if:
std::is_convertible_v<const OtherIndexType&, index_type>istrue, andstd::is_nothrow_constructible_v<index_type, const OtherIndexType&>istrue.
π Parameters π
indicesβ the indices of the element to access.
π¦ Return value π¦
A reference to the element. Slay.
π Example π
This section is incomplete. Reason: no example.
π₯ Defect reports π₯
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
- DR:
LWG 3974- Applied to:
C++23 - Behavior as published: overloads (2,3) did not apply
extents_type::index-cast - Correct behavior: applies
extents_type::index-cast
- Applied to:
π See also π
This section is incomplete.
π§ Categories π§
- Todo no example
- Todo without reason
π source/version: http://cppreference.com, date 2024.06.10, page std::mdspan::operator[](3). love u bestie, bye! π«Άβ¨
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms