Skip to content

P1227R2 Signed ssize() functions, unsigned size() functions #2722

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 27 additions & 41 deletions source/containers.tex
Original file line number Diff line number Diff line change
Expand Up @@ -10278,23 +10278,19 @@
\begin{codeblock}
namespace std {
// constants
inline constexpr ptrdiff_t dynamic_extent = -1;
inline constexpr size_t dynamic_extent = numeric_limits<size_t>::max();

// \ref{views.span}, class template span
template<class ElementType, ptrdiff_t Extent = dynamic_extent>
template<class ElementType, size_t Extent = dynamic_extent>
class span;

// \ref{span.objectrep}, views of object representation
template<class ElementType, ptrdiff_t Extent>
span<const byte,
Extent == dynamic_extent ? dynamic_extent
: static_cast<ptrdiff_t>(sizeof(ElementType)) * Extent>
template<class ElementType, size_t Extent>
span<const byte, Extent == dynamic_extent ? dynamic_extent : sizeof(ElementType) * Extent>
as_bytes(span<ElementType, Extent> s) noexcept;

template<class ElementType, ptrdiff_t Extent>
span<byte,
Extent == dynamic_extent ? dynamic_extent
: static_cast<ptrdiff_t>(sizeof(ElementType)) * Extent>
template<class ElementType, size_t Extent>
span<byte, Extent == dynamic_extent ? dynamic_extent : sizeof(ElementType) * Extent>
as_writable_bytes(span<ElementType, Extent> s) noexcept;
}
\end{codeblock}
Expand Down Expand Up @@ -10325,13 +10321,13 @@
\indexlibrary{\idxcode{span}}%
\begin{codeblock}
namespace std {
template<class ElementType, ptrdiff_t Extent = dynamic_extent>
template<class ElementType, size_t Extent = dynamic_extent>
class span {
public:
// constants and types
using element_type = ElementType;
using value_type = remove_cv_t<ElementType>;
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*;
Expand All @@ -10358,19 +10354,19 @@
template<class Container>
constexpr span(const Container& cont);
constexpr span(const span& other) noexcept = default;
template<class OtherElementType, ptrdiff_t OtherExtent>
template<class OtherElementType, size_t OtherExtent>
constexpr span(const span<OtherElementType, OtherExtent>& s) noexcept;

~span() noexcept = default;

constexpr span& operator=(const span& other) noexcept = default;

// \ref{span.sub}, subviews
template<ptrdiff_t Count>
template<size_t Count>
constexpr span<element_type, Count> first() const;
template<ptrdiff_t Count>
template<size_t Count>
constexpr span<element_type, Count> last() const;
template<ptrdiff_t Offset, ptrdiff_t Count = dynamic_extent>
template<size_t Offset, size_t Count = dynamic_extent>
constexpr span<element_type, @\seebelow@> subspan() const;

constexpr span<element_type, dynamic_extent> first(index_type count) const;
Expand Down Expand Up @@ -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}%
Expand Down Expand Up @@ -10559,7 +10551,7 @@

\indexlibrary{\idxcode{span}!constructor}%
\begin{itemdecl}
template<class OtherElementType, ptrdiff_t OtherExtent>
template<class OtherElementType, size_t OtherExtent>
constexpr span(const span<OtherElementType, OtherExtent>& s) noexcept;
\end{itemdecl}
\begin{itemdescr}
Expand Down Expand Up @@ -10594,12 +10586,12 @@

\indexlibrarymember{span}{first}%
\begin{itemdecl}
template<ptrdiff_t Count> constexpr span<element_type, Count> first() const;
template<size_t Count> constexpr span<element_type, Count> first() const;
\end{itemdecl}
\begin{itemdescr}
\pnum
\expects
\tcode{0 <= Count \&\& Count <= size()} is \tcode{true}.
\tcode{Count <= size()} is \tcode{true}.

\pnum
\effects
Expand All @@ -10608,12 +10600,12 @@

\indexlibrarymember{span}{last}%
\begin{itemdecl}
template<ptrdiff_t Count> constexpr span<element_type, Count> last() const;
template<size_t Count> constexpr span<element_type, Count> last() const;
\end{itemdecl}
\begin{itemdescr}
\pnum
\expects
\tcode{0 <= Count \&\& Count <= size()} is \tcode{true}.
\tcode{Count <= size()} is \tcode{true}.

\pnum
\effects
Expand All @@ -10622,15 +10614,14 @@

\indexlibrarymember{span}{subspan}%
\begin{itemdecl}
template<ptrdiff_t Offset, ptrdiff_t Count = dynamic_extent>
template<size_t Offset, size_t Count = dynamic_extent>
constexpr span<element_type, @\seebelow@> 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}.

Expand Down Expand Up @@ -10659,7 +10650,7 @@
\begin{itemdescr}
\pnum
\expects
\tcode{0 <= count \&\& count <= size()} is \tcode{true}.
\tcode{count <= size()} is \tcode{true}.

\pnum
\effects
Expand All @@ -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
Expand All @@ -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}.

Expand Down Expand Up @@ -10745,7 +10735,7 @@
\begin{itemdescr}
\pnum
\expects
\tcode{0 <= idx \&\& idx < size()} is \tcode{true}.
\tcode{idx < size()} is \tcode{true}.

\pnum
\effects
Expand Down Expand Up @@ -10853,10 +10843,8 @@

\indexlibrary{\idxcode{as_bytes}}%
\begin{itemdecl}
template<class ElementType, ptrdiff_t Extent>
span<const byte,
Extent == dynamic_extent ? dynamic_extent
: static_cast<ptrdiff_t>(sizeof(ElementType)) * Extent>
template<class ElementType, size_t Extent>
span<const byte, Extent == dynamic_extent ? dynamic_extent : sizeof(ElementType) * Extent>
as_bytes(span<ElementType, Extent> s) noexcept;
\end{itemdecl}
\begin{itemdescr}
Expand All @@ -10867,10 +10855,8 @@

\indexlibrary{\idxcode{as_writable_bytes}}%
\begin{itemdecl}
template<class ElementType, ptrdiff_t Extent>
span<byte,
Extent == dynamic_extent ? dynamic_extent
: static_cast<ptrdiff_t>(sizeof(ElementType)) * Extent>
template<class ElementType, size_t Extent>
span<byte, Extent == dynamic_extent ? dynamic_extent : sizeof(ElementType) * Extent>
as_writable_bytes(span<ElementType, Extent> s) noexcept;
\end{itemdecl}
\begin{itemdescr}
Expand Down
23 changes: 23 additions & 0 deletions source/iterators.tex
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,9 @@

template<class C> constexpr auto size(const C& c) -> decltype(c.size());
template<class T, size_t N> constexpr size_t size(const T (&array)[N]) noexcept;
template<class C> constexpr auto ssize(const C& c)
-> common_type_t<ptrdiff_t, make_signed_t<decltype(c.size())>>;
template<class T, ptrdiff_t N> constexpr ptrdiff_t ssize(const T (&array)[N]) noexcept;
template<class C> [[nodiscard]] constexpr auto empty(const C& c) -> decltype(c.empty());
template<class T, size_t N> [[nodiscard]] constexpr bool empty(const T (&array)[N]) noexcept;
template<class E> [[nodiscard]] constexpr bool empty(initializer_list<E> il) noexcept;
Expand Down Expand Up @@ -6467,6 +6470,26 @@
\pnum \returns \tcode{N}.
\end{itemdescr}

\indexlibrary{\idxcode{ssize(C\& c)}}%
\begin{itemdecl}
template <class C> constexpr auto ssize(const C& c)
-> common_type_t<ptrdiff_t, make_signed_t<decltype(c.size())>>;
\end{itemdecl}
\begin{itemdescr}
\pnum \returns
\begin{codeblock}
static_cast<common_type_t<ptrdiff_t, make_signed_t<decltype(c.size())>>>(c.size())
\end{codeblock}
\end{itemdescr}

\indexlibrary{\idxcode{ssize(T (\&array)[N])}}%
\begin{itemdecl}
template <class T, ptrdiff_t N> 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<class C> [[nodiscard]] constexpr auto empty(const C& c) -> decltype(c.empty());
Expand Down