From d2a42fbbc2de0850bfac15a1d689a9c2abaca423 Mon Sep 17 00:00:00 2001 From: Jens Maurer Date: Thu, 14 Nov 2019 09:45:12 +0100 Subject: [PATCH 1/3] P1394R4 Range constructor for std::span Converted run-on sentences in bulleted lists to one sentence per bullet. Fixes NB US 233, US 246, PL 251 (C++20 CD). --- source/containers.tex | 156 +++++++++++++++++++++++++++++++----------- 1 file changed, 115 insertions(+), 41 deletions(-) diff --git a/source/containers.tex b/source/containers.tex index 4c072e4805..75c0994218 100644 --- a/source/containers.tex +++ b/source/containers.tex @@ -10571,18 +10571,18 @@ // \ref{span.cons}, constructors, copy, and assignment constexpr span() noexcept; - constexpr span(pointer ptr, size_type count); - constexpr span(pointer first, pointer last); + template + constexpr span(It first, size_type count); + tmeplate + constexpr span(It first, End last); template constexpr span(element_type (&arr)[N]) noexcept; template constexpr span(array& arr) noexcept; template constexpr span(const array& arr) noexcept; - template - constexpr span(Container& cont); - template - constexpr span(const Container& cont); + template + constexpr span(R&& r); constexpr span(const span& other) noexcept = default; template constexpr span(const span& s) noexcept; @@ -10633,16 +10633,16 @@ size_type size_; // \expos }; + template + span(It, End) -> span>>; template span(T (&)[N]) -> span; template span(array&) -> span; template span(const array&) -> span; - template - span(Container&) -> span; - template - span(const Container&) -> span; + template + span(R&&) -> span>>; } \end{codeblock} @@ -10669,52 +10669,88 @@ \indexlibraryctor{span}% \begin{itemdecl} -constexpr span(pointer ptr, size_type count); +template + constexpr span(It first, size_type count); \end{itemdecl} \begin{itemdescr} +\pnum +\constraints +\begin{itemize} +\item \tcode{It} satisfies \libconcept{contiguous_iterator}. +\item +\begin{codeblock} +{is_convertible_v>(*)[], element_type(*)[]> +\end{codeblock} +is \tcode{true}. +\begin{note} +The intent is to allow only qualification conversions +of the iterator reference type to \tcode{element_type}. +\end{note} +\end{itemize} + \pnum \expects -\range{ptr}{ptr + count} is a valid range. +\begin{itemize} +\item \range{first}{first + count} is a valid range. +\item \tcode{It} models \libconcept{contiguous_iterator}. +\item If \tcode{extent} is not equal to \tcode{dynamic_extent}, then \tcode{count} is equal to \tcode{extent}. +\end{itemize} \pnum \effects -Constructs a \tcode{span} that is a view over the range \range{ptr}{ptr + count}. - -\pnum -\ensures -\tcode{size() == count \&\& data() == ptr}. +Initializes \tcode{data_} with \tcode{to_address(first)} and +\tcode{size_} with \tcode{first + count}. \pnum \throws -Nothing. +When and what \tcode{to_address(first)} throws. \end{itemdescr} \indexlibraryctor{span}% \begin{itemdecl} -constexpr span(pointer first, pointer last); +template + constexpr span(It first, End last); \end{itemdecl} \begin{itemdescr} \pnum +\constraints +\begin{itemize} +\item +\begin{codeblock} +is_convertible_v>(*)[], element_type(*)[]> +\end{codeblock} +is \tcode{true}. +\begin{note} +The intent is to allow only qualification conversions +of the iterator reference type to \tcode{element_type}. +\end{note} +\item \tcode{It} satisfies \libconcept{contiguous_iterator}. +\item \tcode{End} satisfies \tcode{\libconcept{sized_sentinel_for}}. +\item \tcode{is_convertible_v} is \tcode{false}. +\end{itemize} + \expects -\range{first}{last} is a valid range. +\begin{itemize} +\item If \tcode{extent} is not equal to \tcode{dynamic_extent}, then \tcode{last - first} is equal to \tcode{extent}. +\item \range{first}{last} is a valid range. +\item \tcode{It} models \libconcept{contiguous_iterator}. +\item \tcode{End} models \tcode{\libconcept{sized_sentinel_for}}. +\end{itemize} \pnum \effects -Constructs a span that is a view over the range \range{first}{last}. - -\pnum -\ensures -\tcode{size() == last - first \&\& data() == first}. +Initializes \tcode{data_} with \tcode{to_address(first)} and +\tcode{size_} with \tcode{last - first}. \pnum \throws -Nothing. +When and what \tcode{to_address(first)} throws. \end{itemdescr} \indexlibraryctor{span}% @@ -10743,37 +10779,49 @@ \indexlibraryctor{span}% \begin{itemdecl} -template constexpr span(Container& cont); -template constexpr span(const Container& cont); +template constexpr span(R&& r); \end{itemdecl} \begin{itemdescr} \pnum \constraints \begin{itemize} -\item \tcode{extent == dynamic_extent} is \tcode{true}, -\item \tcode{Container} is not a specialization of \tcode{span}, -\item \tcode{Container} is not a specialization of \tcode{array}, -\item \tcode{is_array_v} is \tcode{false}, -\item \tcode{data(cont)} and \tcode{size(cont)} are both well-formed, and -\item \tcode{remove_pointer_t(*)[]} is convertible to \tcode{ElementType(*)[]}. +\item \tcode{extent == dynamic_extent} is \tcode{true}. +\item \tcode{R} satisfies \tcode{ranges::\libconcept{contiguous_range}} and + \tcode{ranges::\libconcept{sized_range}}. +\item Either \tcode{R} satisfies \exposconcept{forwarding-range} or +\tcode{is_const_v} is \tcode{true}. +\item \tcode{remove_cvref_t} is not a specialization of \tcode{span}. +\item \tcode{remove_cvref_t} is not a specialization of \tcode{array}. +\item \tcode{is_array_v>} is \tcode{false}. +\item\relax +\begin{codeblock} +is_convertible_v>(*)[], element_type(*)[]> +\end{codeblock} +is \tcode{true}. +\begin{note} +The intent is to allow only qualification conversions +of the iterator reference type to \tcode{element_type}. +\end{note} \end{itemize} \pnum \expects -\range{data(cont)}{data(cont) + size(cont)} is a valid range. +\begin{itemize} +\item \tcode{R} models \tcode{ranges::\libconcept{contiguous_range}} and +\tcode{ranges::\libconcept{sized_range}}. +\item If \tcode{is_const_v} is \tcode{false}, +\tcode{R} models \exposconcept{forwarding-range}. +\end{itemize} \pnum \effects -Constructs a \tcode{span} that is a view over the range \range{data(cont)}{data(cont) + size(cont)}. - -\pnum -\ensures -\tcode{size() == size(cont) \&\& data() == data(cont)}. +Initializes \tcode{data_} with \tcode{ranges::data(r)} and +\tcode{size_} with \tcode{ranges::size(r)}. \pnum \throws -What and when \tcode{data(cont)} and \tcode{size(cont)} throw. +What and when \tcode{ranges::data(r)} and \tcode{ranges::size(r)} throw. \end{itemdescr} \indexlibraryctor{span}% @@ -10822,6 +10870,32 @@ \tcode{size() == other.size() \&\& data() == other.data()}. \end{itemdescr} +\rSec3[span.deduct]{Deduction guides} + +\indexlibrary{\idxcode{span}!deduction guide}% +\begin{itemdecl} +template + span(It, End) -> span>>; +\end{itemdecl} + +\begin{itemdescr} +\pnum +\constraints +\tcode{It} satisfies \libconcept{contiguous_iterator}. +\end{itemdescr} + +\indexlibrary{\idxcode{span}!deduction guide}% +\begin{itemdecl} +template + span(R&&) -> span>>; +\end{itemdecl} + +\begin{itemdescr} +\pnum +\constraints +\tcode{R} satisfies \tcode{ranges::\libconcept{contiguous_range}}. +\end{itemdescr} + \rSec3[span.sub]{Subviews} \indexlibrarymember{span}{first}% From 6c4806f2704b758b8af506e4f24a4a0931cfdcdf Mon Sep 17 00:00:00 2001 From: Jens Maurer Date: Thu, 14 Nov 2019 10:01:08 +0100 Subject: [PATCH 2/3] [span.cons] Rephrase constraint on input element type to avoid overfull \hbox. --- source/containers.tex | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/source/containers.tex b/source/containers.tex index 75c0994218..621a069a0d 100644 --- a/source/containers.tex +++ b/source/containers.tex @@ -10676,13 +10676,11 @@ \begin{itemdescr} \pnum \constraints +Let \tcode{U} be \tcode{remove_reference_t>}. \begin{itemize} \item \tcode{It} satisfies \libconcept{contiguous_iterator}. \item -\begin{codeblock} -{is_convertible_v>(*)[], element_type(*)[]> -\end{codeblock} -is \tcode{true}. +\tcode{is_convertible_v} is \tcode{true}. \begin{note} The intent is to allow only qualification conversions of the iterator reference type to \tcode{element_type}. @@ -10718,12 +10716,10 @@ \begin{itemdescr} \pnum \constraints +Let \tcode{U} be \tcode{remove_reference_t>}. \begin{itemize} \item -\begin{codeblock} -is_convertible_v>(*)[], element_type(*)[]> -\end{codeblock} -is \tcode{true}. +\tcode{is_convertible_v} is \tcode{true}. \begin{note} The intent is to allow only qualification conversions of the iterator reference type to \tcode{element_type}. @@ -10785,6 +10781,7 @@ \begin{itemdescr} \pnum \constraints +Let \tcode{U} be \tcode{remove_reference_t>}. \begin{itemize} \item \tcode{extent == dynamic_extent} is \tcode{true}. \item \tcode{R} satisfies \tcode{ranges::\libconcept{contiguous_range}} and @@ -10794,11 +10791,8 @@ \item \tcode{remove_cvref_t} is not a specialization of \tcode{span}. \item \tcode{remove_cvref_t} is not a specialization of \tcode{array}. \item \tcode{is_array_v>} is \tcode{false}. -\item\relax -\begin{codeblock} -is_convertible_v>(*)[], element_type(*)[]> -\end{codeblock} -is \tcode{true}. +\item +\tcode{is_convertible_v} is \tcode{true}. \begin{note} The intent is to allow only qualification conversions of the iterator reference type to \tcode{element_type}. @@ -10874,7 +10868,7 @@ \indexlibrary{\idxcode{span}!deduction guide}% \begin{itemdecl} -template +template span(It, End) -> span>>; \end{itemdecl} From 25738f733e5e720fc303effa73da391679750499 Mon Sep 17 00:00:00 2001 From: Jens Maurer Date: Thu, 14 Nov 2019 22:22:17 +0100 Subject: [PATCH 3/3] [span.cons] Do not attempt to initialize size_ with an iterator. --- source/containers.tex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/containers.tex b/source/containers.tex index 621a069a0d..c2aa20e948 100644 --- a/source/containers.tex +++ b/source/containers.tex @@ -10700,7 +10700,7 @@ \pnum \effects Initializes \tcode{data_} with \tcode{to_address(first)} and -\tcode{size_} with \tcode{first + count}. +\tcode{size_} with \tcode{count}. \pnum \throws