Skip to content

Commit 1befda6

Browse files
committed
P1989R2 Range constructor for std::string_view 2: Constrain Harder
1 parent fb3bea8 commit 1befda6

File tree

1 file changed

+55
-1
lines changed

1 file changed

+55
-1
lines changed

source/strings.tex

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4089,6 +4089,8 @@
40894089
constexpr basic_string_view(const charT* str, size_type len);
40904090
template<class It, class End>
40914091
constexpr basic_string_view(It begin, End end);
4092+
template<class R>
4093+
constexpr basic_string_view(R&& r);
40924094

40934095
// \ref{string.view.iterators}, iterator support
40944096
constexpr const_iterator begin() const noexcept;
@@ -4180,6 +4182,9 @@
41804182
// \ref{string.view.deduct}, deduction guide
41814183
template<class It, class End>
41824184
basic_string_view(It, End) -> basic_string_view<iter_value_t<It>>;
4185+
4186+
template<class R>
4187+
basic_string_view(R&&) -> basic_string_view<ranges::range_value_t<R>>;
41834188
}
41844189
\end{codeblock}
41854190

@@ -4279,6 +4284,44 @@
42794284
initializes \tcode{size_} with \tcode{end - begin}.
42804285
\end{itemdescr}
42814286

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

42844327
\indexlibrarymember{const_iterator}{basic_string_view}%
@@ -4954,7 +4997,7 @@
49544997
Otherwise, returns \tcode{npos}.
49554998
\end{itemdescr}
49564999

4957-
\rSec2[string.view.deduct]{Deduction guide}
5000+
\rSec2[string.view.deduct]{Deduction guides}
49585001

49595002
\begin{itemdecl}
49605003
template<class It, class End>
@@ -4970,6 +5013,17 @@
49705013
\end{itemize}
49715014
\end{itemdescr}
49725015

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

49755029
\pnum

0 commit comments

Comments
 (0)