From 7f2493e2e2d34b42a6c12c8806e536d4feb3aee3 Mon Sep 17 00:00:00 2001 From: Jens Maurer Date: Sat, 2 Mar 2019 00:12:53 +0100 Subject: [PATCH] P1227R2 Signed ssize() functions, unsigned size() functions --- source/containers.tex | 68 +++++++++++++++++-------------------------- source/iterators.tex | 23 +++++++++++++++ 2 files changed, 50 insertions(+), 41 deletions(-) diff --git a/source/containers.tex b/source/containers.tex index d8c17ec8c8..379bbcb61b 100644 --- a/source/containers.tex +++ b/source/containers.tex @@ -10278,23 +10278,19 @@ \begin{codeblock} namespace std { // constants - inline constexpr ptrdiff_t dynamic_extent = -1; + inline constexpr size_t dynamic_extent = numeric_limits::max(); // \ref{views.span}, class template span - template + template class span; // \ref{span.objectrep}, views of object representation - template - span(sizeof(ElementType)) * Extent> + template + span as_bytes(span s) noexcept; - template - span(sizeof(ElementType)) * Extent> + template + span as_writable_bytes(span s) noexcept; } \end{codeblock} @@ -10325,13 +10321,13 @@ \indexlibrary{\idxcode{span}}% \begin{codeblock} namespace std { - template + template class span { public: // constants and types using element_type = ElementType; using value_type = remove_cv_t; - using index_type = ptrdiff_t; + using index_type = size_t; using difference_type = ptrdiff_t; using pointer = element_type*; using const_pointer = const element_type*; @@ -10358,7 +10354,7 @@ template constexpr span(const Container& cont); constexpr span(const span& other) noexcept = default; - template + template constexpr span(const span& s) noexcept; ~span() noexcept = default; @@ -10366,11 +10362,11 @@ constexpr span& operator=(const span& other) noexcept = default; // \ref{span.sub}, subviews - template + template constexpr span first() const; - template + template constexpr span last() const; - template + template constexpr span subspan() const; constexpr span first(index_type count) const; @@ -10423,10 +10419,6 @@ \tcode{ElementType} is required to be a complete object type that is not an abstract class type. -\pnum -If \tcode{Extent} is negative and not equal to \tcode{dynamic_extent}, -the program is ill-formed. - \rSec3[span.cons]{Constructors, copy, and assignment} \indexlibrary{\idxcode{span}!constructor}% @@ -10559,7 +10551,7 @@ \indexlibrary{\idxcode{span}!constructor}% \begin{itemdecl} -template +template constexpr span(const span& s) noexcept; \end{itemdecl} \begin{itemdescr} @@ -10594,12 +10586,12 @@ \indexlibrarymember{span}{first}% \begin{itemdecl} -template constexpr span first() const; +template constexpr span first() const; \end{itemdecl} \begin{itemdescr} \pnum \expects -\tcode{0 <= Count \&\& Count <= size()} is \tcode{true}. +\tcode{Count <= size()} is \tcode{true}. \pnum \effects @@ -10608,12 +10600,12 @@ \indexlibrarymember{span}{last}% \begin{itemdecl} -template constexpr span last() const; +template constexpr span last() const; \end{itemdecl} \begin{itemdescr} \pnum \expects -\tcode{0 <= Count \&\& Count <= size()} is \tcode{true}. +\tcode{Count <= size()} is \tcode{true}. \pnum \effects @@ -10622,15 +10614,14 @@ \indexlibrarymember{span}{subspan}% \begin{itemdecl} -template +template constexpr span subspan() const; \end{itemdecl} \begin{itemdescr} \pnum \expects \begin{codeblock} -(0 <= Offset && Offset <= size()) -&& (Count == dynamic_extent || Count >= 0 && Offset + Count <= size()) +Offset <= size() && (Count == dynamic_extent || Offset + Count <= size()) \end{codeblock} is \tcode{true}. @@ -10659,7 +10650,7 @@ \begin{itemdescr} \pnum \expects -\tcode{0 <= count \&\& count <= size()} is \tcode{true}. +\tcode{count <= size()} is \tcode{true}. \pnum \effects @@ -10673,7 +10664,7 @@ \begin{itemdescr} \pnum \expects -\tcode{0 <= count 0 \&\& count <= size()} is \tcode{true}. +\tcode{count <= size()} is \tcode{true}. \pnum \effects @@ -10689,8 +10680,7 @@ \pnum \expects \begin{codeblock} -(0 <= offset && offset <= size()) -&& (count == dynamic_extent || count >= 0 && offset + count <= size()) +offset <= size() && (count == dynamic_extent || offset + count <= size()) \end{codeblock} is \tcode{true}. @@ -10745,7 +10735,7 @@ \begin{itemdescr} \pnum \expects -\tcode{0 <= idx \&\& idx < size()} is \tcode{true}. +\tcode{idx < size()} is \tcode{true}. \pnum \effects @@ -10853,10 +10843,8 @@ \indexlibrary{\idxcode{as_bytes}}% \begin{itemdecl} -template - span(sizeof(ElementType)) * Extent> +template + span as_bytes(span s) noexcept; \end{itemdecl} \begin{itemdescr} @@ -10867,10 +10855,8 @@ \indexlibrary{\idxcode{as_writable_bytes}}% \begin{itemdecl} -template - span(sizeof(ElementType)) * Extent> +template + span as_writable_bytes(span s) noexcept; \end{itemdecl} \begin{itemdescr} diff --git a/source/iterators.tex b/source/iterators.tex index b67256a639..6520a88bad 100644 --- a/source/iterators.tex +++ b/source/iterators.tex @@ -438,6 +438,9 @@ template constexpr auto size(const C& c) -> decltype(c.size()); template constexpr size_t size(const T (&array)[N]) noexcept; + template constexpr auto ssize(const C& c) + -> common_type_t>; + template constexpr ptrdiff_t ssize(const T (&array)[N]) noexcept; template [[nodiscard]] constexpr auto empty(const C& c) -> decltype(c.empty()); template [[nodiscard]] constexpr bool empty(const T (&array)[N]) noexcept; template [[nodiscard]] constexpr bool empty(initializer_list il) noexcept; @@ -6467,6 +6470,26 @@ \pnum \returns \tcode{N}. \end{itemdescr} +\indexlibrary{\idxcode{ssize(C\& c)}}% +\begin{itemdecl} +template constexpr auto ssize(const C& c) + -> common_type_t>; +\end{itemdecl} +\begin{itemdescr} +\pnum \returns +\begin{codeblock} +static_cast>>(c.size()) +\end{codeblock} +\end{itemdescr} + +\indexlibrary{\idxcode{ssize(T (\&array)[N])}}% +\begin{itemdecl} +template constexpr ptrdiff_t ssize(const T (&array)[N]) noexcept; +\end{itemdecl} +\begin{itemdescr} +\pnum \returns \tcode{N}. +\end{itemdescr} + \indexlibrary{\idxcode{empty(C\& c)}}% \begin{itemdecl} template [[nodiscard]] constexpr auto empty(const C& c) -> decltype(c.empty());