Skip to content

P1989R2 Range constructor for std::string_view 2: Constrain Harder #4676

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 16, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 56 additions & 2 deletions source/strings.tex
Original file line number Diff line number Diff line change
Expand Up @@ -4091,6 +4091,8 @@
constexpr basic_string_view(const charT* str, size_type len);
template<class It, class End>
constexpr basic_string_view(It begin, End end);
template<class R>
constexpr basic_string_view(R&& r);

// \ref{string.view.iterators}, iterator support
constexpr const_iterator begin() const noexcept;
Expand Down Expand Up @@ -4179,9 +4181,11 @@
size_type size_; // \expos
};

// \ref{string.view.deduct}, deduction guide
// \ref{string.view.deduct}, deduction guides
template<class It, class End>
basic_string_view(It, End) -> basic_string_view<iter_value_t<It>>;
template<class R>
basic_string_view(R&&) -> basic_string_view<ranges::range_value_t<R>>;
}
\end{codeblock}

Expand Down Expand Up @@ -4281,6 +4285,45 @@
initializes \tcode{size_} with \tcode{end - begin}.
\end{itemdescr}

\indexlibraryctor{basic_string_view}%
\begin{itemdecl}
template<class R>
constexpr basic_string_view(R&& r);
\end{itemdecl}

\begin{itemdescr}
\pnum
Let \tcode{d} be an lvalue of type \tcode{remove_cvref_t<R>}.

\pnum
\constraints
\begin{itemize}
\item
\tcode{R} models
\tcode{ranges::\libconcept{contiguous_range}} and \tcode{ranges::\libconcept{sized_range}},
\item
\tcode{is_same_v<ranges::range_value_t<R>, charT>} is \tcode{true},
\item
\tcode{is_convertible_v<R, const charT*>} is \tcode{false},
\item
\tcode{d.operator ::std::basic_string_view<charT, traits>()}
is not a valid expression, and
\item
if the \grammarterm{qualified-id} \tcode{remove_reference_t<R>::traits_type}
is valid and denotes a type,
\tcode{is_same_v<remove_reference_t<R>::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}%
Expand Down Expand Up @@ -4956,7 +4999,7 @@
Otherwise, returns \tcode{npos}.
\end{itemdescr}

\rSec2[string.view.deduct]{Deduction guide}
\rSec2[string.view.deduct]{Deduction guides}

\begin{itemdecl}
template<class It, class End>
Expand All @@ -4972,6 +5015,17 @@
\end{itemize}
\end{itemdescr}

\begin{itemdecl}
template<class R>
basic_string_view(R&&) -> basic_string_view<ranges::range_value_t<R>>;
\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
Expand Down