Skip to content

Commit 419ea29

Browse files
authored
Merge 2021-06 LWG Motion 12
P1989R2 Range constructor for std::string_view 2: Constrain Harder
2 parents 140404f + c3c40a3 commit 419ea29

File tree

1 file changed

+56
-2
lines changed

1 file changed

+56
-2
lines changed

source/strings.tex

Lines changed: 56 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,45 @@
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{remove_reference_t<R>::traits_type}
4313+
is valid and denotes a type,
4314+
\tcode{is_same_v<remove_reference_t<R>::traits_type, traits>} is \tcode{true}.
4315+
\end{itemize}
4316+
4317+
\pnum
4318+
\effects
4319+
Initializes \tcode{data_} with \tcode{ranges::data(r)} and
4320+
\tcode{size_} with \tcode{ranges::size(r)}.
4321+
4322+
\pnum
4323+
\throws
4324+
Any exception thrown by \tcode{ranges::data(r)} and \tcode{ranges::size(r)}.
4325+
\end{itemdescr}
4326+
42844327
\rSec3[string.view.iterators]{Iterator support}
42854328

42864329
\indexlibrarymember{const_iterator}{basic_string_view}%
@@ -4956,7 +4999,7 @@
49564999
Otherwise, returns \tcode{npos}.
49575000
\end{itemdescr}
49585001

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

49615004
\begin{itemdecl}
49625005
template<class It, class End>
@@ -4972,6 +5015,17 @@
49725015
\end{itemize}
49735016
\end{itemdescr}
49745017

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

49775031
\pnum

0 commit comments

Comments
 (0)