[mdspan.mdspan.members]

# 23 Containers library [[containers]](./#containers)

## 23.7 Views [[views]](views#mdspan.mdspan.members)

### 23.7.3 Multidimensional access [[views.multidim]](views.multidim#mdspan.mdspan.members)

#### 23.7.3.6 Class template mdspan [[mdspan.mdspan]](mdspan.mdspan#members)

#### 23.7.3.6.3 Members [mdspan.mdspan.members]

[ð](#lib:operator%5b%5d,mdspan)

`template<class... OtherIndexTypes>
  constexpr reference operator[](OtherIndexTypes... indices) const;
`

[1](#1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L25086)

*Constraints*: 

- [(1.1)](#1.1)

(is_convertible_v<OtherIndexTypes, index_type> && ...) is true,

- [(1.2)](#1.2)

(is_nothrow_constructible_v<index_type, OtherIndexTypes> && ...) is true, and

- [(1.3)](#1.3)

sizeof...(OtherIndexTypes) == rank() is true[.](#1.sentence-1)

[2](#2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L25097)

Let I be extents_type​::​*index-cast*(std​::​move(indices))[.](#2.sentence-1)

[3](#3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L25100)

*Hardened preconditions*: I is a multidimensional index in extents()[.](#3.sentence-1)

[*Note [1](#note-1)*:

This implies that*map_*(I) < *map_*.required_span_size() is true[.](#3.sentence-2)

â *end note*]

[4](#4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L25109)

*Effects*: Equivalent to:return *acc_*.access(*ptr_*, *map_*(static_cast<index_type>(std::move(indices))...));

[ð](#lib:operator%5b%5d,mdspan_)

`template<class OtherIndexType>
  constexpr reference operator[](span<OtherIndexType, rank()> indices) const;
template<class OtherIndexType>
  constexpr reference operator[](const array<OtherIndexType, rank()>& indices) const;
`

[5](#5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L25126)

*Constraints*: 

- [(5.1)](#5.1)

is_convertible_v<const OtherIndexType&, index_type> is true, and

- [(5.2)](#5.2)

is_nothrow_constructible_v<index_type, const OtherIndexType&> is true[.](#5.sentence-1)

[6](#6)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L25135)

*Effects*: Let P be a parameter pack such thatis_same_v<make_index_sequence<rank()>, index_sequence<P...>> is true[.](#6.sentence-1)

Equivalent to:return operator[](extents_type::*index-cast*(as_const(indices[P]))...);

[ð](#lib:at,mdspan)

`template<class... OtherIndexTypes>
  constexpr reference at(OtherIndexTypes... indices) const;
`

[7](#7)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L25155)

*Constraints*: 

- [(7.1)](#7.1)

(is_convertible_v<OtherIndexTypes, index_type> && ...) is true,

- [(7.2)](#7.2)

(is_nothrow_constructible_v<index_type, OtherIndexTypes> && ...) is true, and

- [(7.3)](#7.3)

sizeof...(OtherIndexTypes) == rank() is true[.](#7.sentence-1)

[8](#8)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L25166)

Let I be extents_type​::​*index-cast*(std​::​move(indices))[.](#8.sentence-1)

[9](#9)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L25169)

*Returns*: (*this)[I...][.](#9.sentence-1)

[10](#10)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L25173)

*Throws*: out_of_range if I is not a multidimensional index in extents()[.](#10.sentence-1)

[ð](#lib:at,mdspan_)

`template<class OtherIndexType>
  constexpr reference at(span<OtherIndexType, rank()> indices) const;
template<class OtherIndexType>
  constexpr reference at(const array<OtherIndexType, rank()>& indices) const;
`

[11](#11)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L25187)

*Constraints*: 

- [(11.1)](#11.1)

is_convertible_v<const OtherIndexType&, index_type> is true, and

- [(11.2)](#11.2)

is_nothrow_constructible_v<index_type, const OtherIndexType&> is true[.](#11.sentence-1)

[12](#12)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L25196)

*Effects*: Let P be a parameter pack such thatis_same_v<make_index_sequence<rank()>, index_sequence<P...>> is true[.](#12.sentence-1)

Equivalent to:return at(extents_type::*index-cast*(as_const(indices[P]))...);

[ð](#lib:size,mdspan)

`constexpr size_type size() const noexcept;
`

[13](#13)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L25215)

*Preconditions*: The size of the multidimensional index space extents() is representable as a value of type size_type ([[basic.fundamental]](basic.fundamental "6.9.2 Fundamental types"))[.](#13.sentence-1)

[14](#14)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L25220)

*Returns*: extents().*fwd-prod-of-extents*(rank())[.](#14.sentence-1)

[ð](#lib:empty,mdspan)

`constexpr bool empty() const noexcept;
`

[15](#15)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L25231)

*Returns*: true if the size of the multidimensional index space extents() is 0,
otherwise false[.](#15.sentence-1)

[ð](#lib:swap,mdspan)

`friend constexpr void swap(mdspan& x, mdspan& y) noexcept;
`

[16](#16)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L25244)

*Effects*: Equivalent to:swap(x.*ptr_*, y.*ptr_*);
swap(x.*map_*, y.*map_*);
swap(x.*acc_*, y.*acc_*);
