Skip to content

Commit 17bdb94

Browse files
committed
P3383R3 mdspan.at()
Fixes #7951 Fixes cplusplus/papers#2040
1 parent 4726d67 commit 17bdb94

File tree

1 file changed

+70
-2
lines changed

1 file changed

+70
-2
lines changed

source/containers.tex

Lines changed: 70 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21034,7 +21034,7 @@
2103421034

2103521035
\indexheader{mdspan}%
2103621036
\begin{codeblock}
21037-
// all freestanding
21037+
// mostly freestanding
2103821038
namespace std {
2103921039
// \ref{mdspan.extents}, class template \tcode{extents}
2104021040
template<class IndexType, size_t... Extents>
@@ -21068,7 +21068,7 @@
2106821068
// \ref{mdspan.mdspan}, class template \tcode{mdspan}
2106921069
template<class ElementType, class Extents, class LayoutPolicy = layout_right,
2107021070
class AccessorPolicy = default_accessor<ElementType>>
21071-
class mdspan;
21071+
class mdspan; // partially freestanding
2107221072

2107321073
// \ref{mdspan.sub}, \tcode{submdspan} creation
2107421074
template<class OffsetType, class LengthType, class StrideType>
@@ -24691,6 +24691,13 @@
2469124691
template<class OtherIndexType>
2469224692
constexpr reference operator[](const array<OtherIndexType, rank()>& indices) const;
2469324693

24694+
template<class... OtherIndexTypes>
24695+
constexpr reference at(OtherIndexTypes... indices) const; // freestanding-deleted
24696+
template<class OtherIndexType>
24697+
constexpr reference at(span<OtherIndexType, rank()> indices) const; // freestanding-deleted
24698+
template<class OtherIndexType>
24699+
constexpr reference at(const array<OtherIndexType, rank()>& indices) const; // freestanding-deleted
24700+
2469424701
constexpr size_type size() const noexcept;
2469524702
constexpr bool empty() const noexcept;
2469624703

@@ -25139,6 +25146,67 @@
2513925146
\end{codeblock}
2514025147
\end{itemdescr}
2514125148

25149+
\indexlibrarymember{at}{mdspan}%
25150+
\begin{itemdecl}
25151+
template<class... OtherIndexTypes>
25152+
constexpr reference at(OtherIndexTypes... indices) const;
25153+
\end{itemdecl}
25154+
25155+
\begin{itemdescr}
25156+
\pnum
25157+
\constraints
25158+
\begin{itemize}
25159+
\item
25160+
\tcode{(is_convertible_v<OtherIndexTypes, index_type> \&\& ...)} is \tcode{true},
25161+
\item
25162+
\tcode{(is_nothrow_constructible_v<index_type, OtherIndexTypes> \&\& ...)} is \tcode{true}, and
25163+
\item
25164+
\tcode{sizeof...(OtherIndexTypes) == rank()} is \tcode{true}.
25165+
\end{itemize}
25166+
25167+
\pnum
25168+
Let \tcode{I} be \tcode{extents_type::\exposid{index-cast}(std::move(indices))}.
25169+
25170+
\pnum
25171+
\returns
25172+
\tcode{(*this)[I...]}.
25173+
25174+
\pnum
25175+
\throws
25176+
\tcode{out_of_range} if \tcode{I} is not a multidimensional index in \tcode{extents()}.
25177+
\end{itemdescr}
25178+
25179+
\indexlibrarymember{at}{mdspan}%
25180+
\begin{itemdecl}
25181+
template<class OtherIndexType>
25182+
constexpr reference at(span<OtherIndexType, rank()> indices) const;
25183+
template<class OtherIndexType>
25184+
constexpr reference at(const array<OtherIndexType, rank()>& indices) const;
25185+
\end{itemdecl}
25186+
25187+
\begin{itemdescr}
25188+
\pnum
25189+
\constraints
25190+
\begin{itemize}
25191+
\item
25192+
\tcode{is_convertible_v<const OtherIndexType\&, index_type>} is \tcode{true}, and
25193+
\item
25194+
\tcode{is_nothrow_constructible_v<index_type, const OtherIndexType\&>} is \tcode{true}.
25195+
\end{itemize}
25196+
25197+
\pnum
25198+
\effects
25199+
Let \tcode{P} be a parameter pack such that
25200+
\begin{codeblock}
25201+
is_same_v<make_index_sequence<rank()>, index_sequence<P...>>
25202+
\end{codeblock}
25203+
is \tcode{true}.
25204+
Equivalent to:
25205+
\begin{codeblock}
25206+
return at(extents_type::@\exposid{index-cast}@(as_const(indices[P]))...);
25207+
\end{codeblock}
25208+
\end{itemdescr}
25209+
2514225210
\indexlibrarymember{size}{mdspan}%
2514325211
\begin{itemdecl}
2514425212
constexpr size_type size() const noexcept;

0 commit comments

Comments
 (0)