Skip to content

Commit d447003

Browse files
jensmaurertkoeppe
authored andcommitted
P1989R2 Range constructor for std::string_view 2: Constrain Harder
1 parent 140404f commit d447003

File tree

1 file changed

+55
-2
lines changed

1 file changed

+55
-2
lines changed

source/strings.tex

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4091,6 +4091,8 @@
40914091
constexpr basic_string_view(const charT* str, size_type len);
40924092
template<class It, class End>
40934093
constexpr basic_string_view(It begin, End end);
4094+
template<class R>
4095+
constexpr basic_string_view(R&& r);
40944096

40954097
// \ref{string.view.iterators}, iterator support
40964098
constexpr const_iterator begin() const noexcept;
@@ -4179,9 +4181,11 @@
41794181
size_type size_; // \expos
41804182
};
41814183

4182-
// \ref{string.view.deduct}, deduction guide
4184+
// \ref{string.view.deduct}, deduction guides
41834185
template<class It, class End>
41844186
basic_string_view(It, End) -> basic_string_view<iter_value_t<It>>;
4187+
template<class R>
4188+
basic_string_view(R&&) -> basic_string_view<ranges::range_value_t<R>>;
41854189
}
41864190
\end{codeblock}
41874191

@@ -4281,6 +4285,44 @@
42814285
initializes \tcode{size_} with \tcode{end - begin}.
42824286
\end{itemdescr}
42834287

4288+
\indexlibraryctor{basic_string_view}%
4289+
\begin{itemdecl}
4290+
template<class R>
4291+
constexpr basic_string_view(R&& r);
4292+
\end{itemdecl}
4293+
4294+
\begin{itemdescr}
4295+
\pnum
4296+
Let \tcode{d} be an lvalue of type \tcode{remove_cvref_t<R>}.
4297+
4298+
\pnum
4299+
\constraints
4300+
\begin{itemize}
4301+
\item
4302+
\tcode{R} models
4303+
\tcode{ranges::\libconcept{contiguous_range}} and \tcode{ranges::\libconcept{sized_range}},
4304+
\item
4305+
\tcode{is_same_v<ranges::range_value_t<R>, charT>} is \tcode{true},
4306+
\item
4307+
\tcode{is_convertible_v<R, const charT*>} is \tcode{false},
4308+
\item
4309+
\tcode{d.operator ::std::basic_string_view<charT, traits>()}
4310+
is not a valid expression, and
4311+
\item
4312+
if the \grammarterm{qualified-id} \tcode{R::traits_type} is valid and denotes a type,
4313+
\tcode{is_same_v<remove_reference_t<R>::traits_type, traits>} is \tcode{true}.
4314+
\end{itemize}
4315+
4316+
\pnum
4317+
\effects
4318+
Initializes \tcode{data_} with \tcode{ranges::data(r)} and
4319+
\tcode{size_} with \tcode{ranges::size(r)}.
4320+
4321+
\pnum
4322+
\throws
4323+
Any exception thrown by \tcode{ranges::data(r)} and \tcode{ranges::size(r)}.
4324+
\end{itemdescr}
4325+
42844326
\rSec3[string.view.iterators]{Iterator support}
42854327

42864328
\indexlibrarymember{const_iterator}{basic_string_view}%
@@ -4956,7 +4998,7 @@
49564998
Otherwise, returns \tcode{npos}.
49574999
\end{itemdescr}
49585000

4959-
\rSec2[string.view.deduct]{Deduction guide}
5001+
\rSec2[string.view.deduct]{Deduction guides}
49605002

49615003
\begin{itemdecl}
49625004
template<class It, class End>
@@ -4972,6 +5014,17 @@
49725014
\end{itemize}
49735015
\end{itemdescr}
49745016

5017+
\begin{itemdecl}
5018+
template<class R>
5019+
basic_string_view(R&&) -> basic_string_view<ranges::range_value_t<R>>;
5020+
\end{itemdecl}
5021+
5022+
\begin{itemdescr}
5023+
\pnum
5024+
\constraints
5025+
\tcode{R} satisfies \tcode{ranges::\libconcept{contiguous_range}}.
5026+
\end{itemdescr}
5027+
49755028
\rSec2[string.view.comparison]{Non-member comparison functions}
49765029

49775030
\pnum

0 commit comments

Comments
 (0)