std::mdspan::operator[](3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

πŸ’… 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.

  1. 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> && ...) is true,
  • (std::is_nothrow_constructible_v<index_type, OtherIndexTypes> && ...) is true, and
  • sizeof...(OtherIndexTypes) == rank() is true.

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> is true, and
  • std::is_nothrow_constructible_v<index_type, const OtherIndexType&> is true.

πŸŽ€ 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

πŸ‘€ 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