From d44700309e80976055e642fd09a4eee566aa8547 Mon Sep 17 00:00:00 2001 From: Jens Maurer Date: Wed, 9 Jun 2021 18:08:35 +0200 Subject: [PATCH 1/2] P1989R2 Range constructor for std::string_view 2: Constrain Harder --- source/strings.tex | 57 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 55 insertions(+), 2 deletions(-) diff --git a/source/strings.tex b/source/strings.tex index 14bea900d3..6e49e847be 100644 --- a/source/strings.tex +++ b/source/strings.tex @@ -4091,6 +4091,8 @@ constexpr basic_string_view(const charT* str, size_type len); template constexpr basic_string_view(It begin, End end); + template + constexpr basic_string_view(R&& r); // \ref{string.view.iterators}, iterator support constexpr const_iterator begin() const noexcept; @@ -4179,9 +4181,11 @@ size_type size_; // \expos }; - // \ref{string.view.deduct}, deduction guide + // \ref{string.view.deduct}, deduction guides template basic_string_view(It, End) -> basic_string_view>; + template + basic_string_view(R&&) -> basic_string_view>; } \end{codeblock} @@ -4281,6 +4285,44 @@ initializes \tcode{size_} with \tcode{end - begin}. \end{itemdescr} +\indexlibraryctor{basic_string_view}% +\begin{itemdecl} +template + constexpr basic_string_view(R&& r); +\end{itemdecl} + +\begin{itemdescr} +\pnum +Let \tcode{d} be an lvalue of type \tcode{remove_cvref_t}. + +\pnum +\constraints +\begin{itemize} +\item +\tcode{R} models +\tcode{ranges::\libconcept{contiguous_range}} and \tcode{ranges::\libconcept{sized_range}}, +\item +\tcode{is_same_v, charT>} is \tcode{true}, +\item +\tcode{is_convertible_v} is \tcode{false}, +\item +\tcode{d.operator ::std::basic_string_view()} +is not a valid expression, and +\item +if the \grammarterm{qualified-id} \tcode{R::traits_type} is valid and denotes a type, +\tcode{is_same_v::traits_type, traits>} is \tcode{true}. +\end{itemize} + +\pnum +\effects +Initializes \tcode{data_} with \tcode{ranges::data(r)} and +\tcode{size_} with \tcode{ranges::size(r)}. + +\pnum +\throws +Any exception thrown by \tcode{ranges::data(r)} and \tcode{ranges::size(r)}. +\end{itemdescr} + \rSec3[string.view.iterators]{Iterator support} \indexlibrarymember{const_iterator}{basic_string_view}% @@ -4956,7 +4998,7 @@ Otherwise, returns \tcode{npos}. \end{itemdescr} -\rSec2[string.view.deduct]{Deduction guide} +\rSec2[string.view.deduct]{Deduction guides} \begin{itemdecl} template @@ -4972,6 +5014,17 @@ \end{itemize} \end{itemdescr} +\begin{itemdecl} +template + basic_string_view(R&&) -> basic_string_view>; +\end{itemdecl} + +\begin{itemdescr} +\pnum +\constraints +\tcode{R} satisfies \tcode{ranges::\libconcept{contiguous_range}}. +\end{itemdescr} + \rSec2[string.view.comparison]{Non-member comparison functions} \pnum From c3c40a39caab2421f2445805e6d495b25f11a0d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20K=C3=B6ppe?= Date: Thu, 17 Jun 2021 00:00:30 +0100 Subject: [PATCH 2/2] [string.view.cons] Change "R" to "remove_reference_t" in constraint. The reference removal was omitted from P1989R2 accidentally. Without it, the entire constraint item would not apply when R is a reference type, even though it was clearly intended to cover that case. --- source/strings.tex | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/source/strings.tex b/source/strings.tex index 6e49e847be..91a59f4491 100644 --- a/source/strings.tex +++ b/source/strings.tex @@ -4309,7 +4309,8 @@ \tcode{d.operator ::std::basic_string_view()} is not a valid expression, and \item -if the \grammarterm{qualified-id} \tcode{R::traits_type} is valid and denotes a type, +if the \grammarterm{qualified-id} \tcode{remove_reference_t::traits_type} +is valid and denotes a type, \tcode{is_same_v::traits_type, traits>} is \tcode{true}. \end{itemize}