Skip to content

P2494R2 Relaxing range adaptors to allow for move only types #5710

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 3 commits into from
Aug 17, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
81 changes: 45 additions & 36 deletions source/ranges.tex
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@
}

// \ref{range.single}, single view
template<@\libconcept{copy_constructible}@ T>
template<@\libconcept{move_constructible}@ T>
requires is_object_v<T>
class single_view; // freestanding

Expand Down Expand Up @@ -256,7 +256,7 @@
namespace views { inline constexpr @\unspecnc@ filter = @\unspecnc@; } // freestanding

// \ref{range.transform}, transform view
template<@\libconcept{input_range}@ V, @\libconcept{copy_constructible}@ F>
template<@\libconcept{input_range}@ V, @\libconcept{move_constructible}@ F>
requires @\libconcept{view}@<V> && is_object_v<F> &&
@\libconcept{regular_invocable}@<F&, range_reference_t<V>> &&
@\exposconcept{can-reference}@<invoke_result_t<F&, range_reference_t<V>>>
Expand Down Expand Up @@ -421,7 +421,7 @@
namespace views { inline constexpr @\unspecnc@ zip = @\unspecnc@; } // freestanding

// \ref{range.zip.transform}, zip transform view
template<@\libconcept{copy_constructible}@ F, @\libconcept{input_range}@... Views>
template<@\libconcept{move_constructible}@ F, @\libconcept{input_range}@... Views>
requires (@\libconcept{view}@<Views> && ...) && (sizeof...(Views) > 0) && is_object_v<F> &&
@\libconcept{regular_invocable}@<F&, range_reference_t<Views>...> &&
@\exposconcept{can-reference}@<invoke_result_t<F&, range_reference_t<Views>...>>
Expand All @@ -445,7 +445,7 @@
}

// \ref{range.adjacent.transform}, adjacent transform view
template<@\libconcept{forward_range}@ V, @\libconcept{copy_constructible}@ F, size_t N>
template<@\libconcept{forward_range}@ V, @\libconcept{move_constructible}@ F, size_t N>
requires @\seebelow@
class adjacent_transform_view; // freestanding

Expand Down Expand Up @@ -2473,15 +2473,15 @@
\indexlibraryglobal{single_view}%
\begin{codeblock}
namespace std::ranges {
template<@\libconcept{copy_constructible}@ T>
template<@\libconcept{move_constructible}@ T>
requires is_object_v<T>
class single_view : public view_interface<single_view<T>> {
private:
@\exposidnc{copyable-box}@<T> @\exposidnc{value_}@; // \expos{} (see \ref{range.copy.wrap})
@\exposidnc{movable-box}@<T> @\exposidnc{value_}@; // \expos{} (see \ref{range.move.wrap})

public:
single_view() requires @\libconcept{default_initializable}@<T> = default;
constexpr explicit single_view(const T& t);
constexpr explicit single_view(const T& t) requires @\libconcept{copy_constructible}@<T>;
constexpr explicit single_view(T&& t);
template<class... Args>
requires @\libconcept{constructible_from}@<T, Args...>
Expand All @@ -2503,7 +2503,7 @@

\indexlibraryctor{single_view}%
\begin{itemdecl}
constexpr explicit single_view(const T& t);
constexpr explicit single_view(const T& t) requires @\libconcept{copy_constructible}@<T>;;
\end{itemdecl}

\begin{itemdescr}
Expand Down Expand Up @@ -4072,31 +4072,32 @@
the initialization of the bound argument entities of the result,
as specified above, are all well-formed.

\rSec2[range.copy.wrap]{Copyable wrapper}
\rSec2[range.move.wrap]{Movable wrapper}

\pnum
Many types in this subclause are specified in terms of
an exposition-only class template \exposid{copyable-box}.
\tcode{\exposid{copyable-box}<T>} behaves exactly like \tcode{optional<T>}
an exposition-only class template \exposid{movable-box}.
\tcode{\exposid{movable-box}<T>} behaves exactly like \tcode{optional<T>}
with the following differences:
\begin{itemize}
\item \tcode{\exposid{copyable-box}<T>} constrains
\item \tcode{\exposid{movable-box}<T>} constrains
its type parameter \tcode{T} with
\tcode{\libconcept{copy_constructible}<T> \&\& is_object_v<T>}.

\item The default
constructor of \tcode{\exposid{copyable-box}<T>} is equivalent to:
constructor of \tcode{\exposid{movable-box}<T>} is equivalent to:
\begin{codeblock}
constexpr @\exposid{copyable-box}@() noexcept(is_nothrow_default_constructible_v<T>)
constexpr @\exposid{movable-box}@() noexcept(is_nothrow_default_constructible_v<T>)
requires @\libconcept{default_initializable}@<T>
: @\exposid{copyable-box}@{in_place} {}
: @\exposid{movable-box}@{in_place} {}
\end{codeblock}

\item If \tcode{\libconcept{copyable}<T>} is not
modeled, the copy assignment operator is equivalent to:
\begin{codeblock}
constexpr @\exposid{copyable-box}@& operator=(const @\exposid{copyable-box}@& that)
noexcept(is_nothrow_copy_constructible_v<T>) {
constexpr @\exposid{movable-box}@& operator=(const @\exposid{movable-box}@& that)
noexcept(is_nothrow_copy_constructible_v<T>)
requires @\libconcept{copy_constructible}@<T> {
if (this != addressof(that)) {
if (that) emplace(*that);
else reset();
Expand All @@ -4108,7 +4109,7 @@
\item If \tcode{\libconcept{movable}<T>} is not modeled,
the move assignment operator is equivalent to:
\begin{codeblock}
constexpr @\exposid{copyable-box}@& operator=(@\exposid{copyable-box}@&& that)
constexpr @\exposid{movable-box}@& operator=(@\exposid{movable-box}@&& that)
noexcept(is_nothrow_move_constructible_v<T>) {
if (this != addressof(that)) {
if (that) emplace(std::move(*that));
Expand All @@ -4121,10 +4122,18 @@

\pnum
\recommended
\tcode{\exposid{copyable-box}<T>} should store only a \tcode{T}
if either \tcode{T} models \libconcept{copyable} or
\begin{itemize}
\item
If \tcode{\libconcept{copy_constructible}<T>} is \tcode{true},
\tcode{\exposid{movable-box}<T>} should store only a \exposid{T}
if either \tcode{T} models \libconcept{copyable}, or
\tcode{is_nothrow_move_constructible_v<T> \&\& is_nothrow_copy_constructible_v<T>}
is \tcode{true}.
\item
Otherwise, \tcode{\exposid{movable-box}<T>} should store only a \tcode{T}
if either \tcode{T} models \libconcept{movable} or
\tcode{is_nothrow_move_constructible_v<T>} is \tcode{true}.
\end{itemize}

\rSec2[range.nonprop.cache]{Non-propagating cache}

Expand Down Expand Up @@ -4523,7 +4532,7 @@
class filter_view : public view_interface<filter_view<V, Pred>> {
private:
V @\exposid{base_}@ = V(); // \expos
@\exposidnc{copyable-box}@<Pred> @\exposid{pred_}@; // \expos
@\exposidnc{movable-box}@<Pred> @\exposid{pred_}@; // \expos

// \ref{range.filter.iterator}, class \tcode{filter_view::\exposid{iterator}}
class @\exposid{iterator}@; // \expos
Expand Down Expand Up @@ -4943,7 +4952,7 @@
\indexlibrarymember{size}{transform_view}%
\begin{codeblock}
namespace std::ranges {
template<@\libconcept{input_range}@ V, @\libconcept{copy_constructible}@ F>
template<@\libconcept{input_range}@ V, @\libconcept{move_constructible}@ F>
requires @\libconcept{view}@<V> && is_object_v<F> &&
@\libconcept{regular_invocable}@<F&, range_reference_t<V>> &&
@\exposconcept{can-reference}@<invoke_result_t<F&, range_reference_t<V>>>
Expand All @@ -4956,7 +4965,7 @@
template<bool> struct @\exposid{sentinel}@; // \expos

V @\exposid{base_}@ = V(); // \expos
@\placeholdernc{copyable-box}@<F> @\exposid{fun_}@; // \expos
@\placeholdernc{movable-box}@<F> @\exposid{fun_}@; // \expos

public:
transform_view() requires @\libconcept{default_initializable}@<V> && @\libconcept{default_initializable}@<F> = default;
Expand Down Expand Up @@ -5096,7 +5105,7 @@
\indexlibraryglobal{transform_view::iterator}%
\begin{codeblock}
namespace std::ranges {
template<@\libconcept{input_range}@ V, @\libconcept{copy_constructible}@ F>
template<@\libconcept{input_range}@ V, @\libconcept{move_constructible}@ F>
requires @\libconcept{view}@<V> && is_object_v<F> &&
@\libconcept{regular_invocable}@<F&, range_reference_t<V>> &&
@\exposconcept{can-reference}@<invoke_result_t<F&, range_reference_t<V>>>
Expand Down Expand Up @@ -5480,7 +5489,7 @@
\indexlibraryglobal{transform_view::sentinel}%
\begin{codeblock}
namespace std::ranges {
template<@\libconcept{input_range}@ V, @\libconcept{copy_constructible}@ F>
template<@\libconcept{input_range}@ V, @\libconcept{move_constructible}@ F>
requires @\libconcept{view}@<V> && is_object_v<F> &&
@\libconcept{regular_invocable}@<F&, range_reference_t<V>> &&
@\exposconcept{can-reference}@<invoke_result_t<F&, range_reference_t<V>>>
Expand Down Expand Up @@ -5910,7 +5919,7 @@
template<bool> class @\exposidnc{sentinel}@; // \expos

V @\exposid{base_}@ = V(); // \expos
@\exposidnc{copyable-box}@<Pred> @\exposid{pred_}@; // \expos
@\exposidnc{movable-box}@<Pred> @\exposid{pred_}@; // \expos

public:
take_while_view() requires @\libconcept{default_initializable}@<V> && @\libconcept{default_initializable}@<Pred> = default;
Expand Down Expand Up @@ -6277,7 +6286,7 @@

private:
V @\exposid{base_}@ = V(); // \expos
@\placeholder{copyable-box}@<Pred> @\exposid{pred_}@; @\itcorr[-1]@ // \expos
@\placeholder{movable-box}@<Pred> @\exposid{pred_}@; @\itcorr[-1]@ // \expos
};

template<class R, class Pred>
Expand Down Expand Up @@ -10007,12 +10016,12 @@
\indexlibrarymember{size}{zip_transform_view}%
\begin{codeblock}
namespace std::ranges {
template<@\libconcept{copy_constructible}@ F, @\libconcept{input_range}@... Views>
template<@\libconcept{mmove_constructible}@ F, @\libconcept{input_range}@... Views>
requires (@\libconcept{view}@<Views> && ...) && (sizeof...(Views) > 0) && is_object_v<F> &&
@\libconcept{regular_invocable}@<F&, range_reference_t<Views>...> &&
@\exposconcept{can-reference}@<invoke_result_t<F&, range_reference_t<Views>...>>
class zip_transform_view : public view_interface<zip_transform_view<F, Views...>> {
@\exposidnc{copyable-box}@<F> @\exposid{fun_}@; // \expos
@\exposidnc{movable-box}@<F> @\exposid{fun_}@; // \expos
zip_view<Views...> @\exposid{zip_}@; // \expos

using @\exposidnc{InnerView}@ = zip_view<Views...>; // \expos
Expand Down Expand Up @@ -10088,7 +10097,7 @@
\indexlibraryglobal{zip_transform_view::iterator}%
\begin{codeblock}
namespace std::ranges {
template<@\libconcept{copy_constructible}@ F, @\libconcept{input_range}@... Views>
template<@\libconcept{move_constructible}@ F, @\libconcept{input_range}@... Views>
requires (@\libconcept{view}@<Views> && ...) && (sizeof...(Views) > 0) && is_object_v<F> &&
@\libconcept{regular_invocable}@<F&, range_reference_t<Views>...> &&
@\exposconcept{can-reference}@<invoke_result_t<F&, range_reference_t<Views>...>>
Expand Down Expand Up @@ -10400,7 +10409,7 @@
\indexlibraryglobal{zip_transform_view::sentinel}%
\begin{codeblock}
namespace std::ranges {
template<@\libconcept{copy_constructible}@ F, @\libconcept{input_range}@... Views>
template<@\libconcept{move_constructible}@ F, @\libconcept{input_range}@... Views>
requires (@\libconcept{view}@<Views> && ...) && (sizeof...(Views) > 0) && is_object_v<F> &&
@\libconcept{regular_invocable}@<F&, range_reference_t<Views>...> &&
@\exposconcept{can-reference}@<invoke_result_t<F&, range_reference_t<Views>...>>
Expand Down Expand Up @@ -11165,12 +11174,12 @@
\indexlibrarymember{size}{adjacent_transform_view}%
\begin{codeblock}
namespace std::ranges {
template<@\libconcept{forward_range}@ V, @\libconcept{copy_constructible}@ F, size_t N>
template<@\libconcept{forward_range}@ V, @\libconcept{move_constructible}@ F, size_t N>
requires @\libconcept{view}@<V> && (N > 0) && is_object_v<F> &&
@\libconcept{regular_invocable}@<F&, @\exposid{REPEAT}@(range_reference_t<V>, N)...> &&
@\exposconcept{can-reference}@<invoke_result_t<F&, @\exposid{REPEAT}@(range_reference_t<V>, N)...>>
class adjacent_transform_view : public view_interface<adjacent_transform_view<V, F, N>> {
@\exposidnc{copyable-box}@<F> @\exposid{fun_}@; // \expos
@\exposidnc{movable-box}@<F> @\exposid{fun_}@; // \expos
adjacent_view<V, N> @\exposid{inner_}@; // \expos

using @\exposidnc{InnerView}@ = adjacent_view<V, N>; // \expos
Expand Down Expand Up @@ -11244,7 +11253,7 @@
\indexlibraryglobal{adjacent_transform_view::iterator}%
\begin{codeblock}
namespace std::ranges {
template<@\libconcept{forward_range}@ V, @\libconcept{copy_constructible}@ F, size_t N>
template<@\libconcept{forward_range}@ V, @\libconcept{move_constructible}@ F, size_t N>
requires @\libconcept{view}@<V> && (N > 0) && is_object_v<F> &&
@\libconcept{regular_invocable}@<F&, @\exposid{REPEAT}@(range_reference_t<V>, N)...> &&
@\exposconcept{can-reference}@<invoke_result_t<F&, @\exposid{REPEAT}@(range_reference_t<V>, N)...>>
Expand Down Expand Up @@ -11547,7 +11556,7 @@
\indexlibraryglobal{adjacent_transform_view::sentinel}%
\begin{codeblock}
namespace std::ranges {
template<@\libconcept{forward_range}@ V, @\libconcept{copy_constructible}@ F, size_t N>
template<@\libconcept{forward_range}@ V, @\libconcept{move_constructible}@ F, size_t N>
requires @\libconcept{view}@<V> && (N > 0) && is_object_v<F> &&
@\libconcept{regular_invocable}@<F&, @\exposid{REPEAT}@(range_reference_t<V>, N)...> &&
@\exposconcept{can-reference}@<invoke_result_t<F&, @\exposid{REPEAT}@(range_reference_t<V>, N)...>>
Expand Down Expand Up @@ -13293,7 +13302,7 @@
requires @\libconcept{view}@<V> && is_object_v<Pred>
class chunk_by_view : public view_interface<chunk_by_view<V, Pred>> {
V @\exposid{base_}@ = V(); // \expos
@\exposid{copyable-box}@<Pred> @\exposid{pred_}@ = Pred(); // \expos
@\exposid{movable-box}@<Pred> @\exposid{pred_}@ = Pred(); // \expos
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A space is needed before the comment to keep them aligned.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will fix!


// \ref{range.chunk.by.iter}, class \tcode{chunk_by_view::\exposid{iterator}}
class @\exposid{iterator}@; // \expos
Expand Down
2 changes: 1 addition & 1 deletion source/support.tex
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,7 @@
#define @\defnlibxname{cpp_lib_polymorphic_allocator}@ 201902L // also in \libheader{memory_resource}
#define @\defnlibxname{cpp_lib_print}@ 202207L // also in \libheader{print}, \libheader{ostream}
#define @\defnlibxname{cpp_lib_quoted_string_io}@ 201304L // also in \libheader{iomanip}
#define @\defnlibxname{cpp_lib_ranges}@ 202202L
#define @\defnlibxname{cpp_lib_ranges}@ 202207L
// also in \libheader{algorithm}, \libheader{functional}, \libheader{iterator}, \libheader{memory}, \libheader{ranges}
#define @\defnlibxname{cpp_lib_ranges_as_const}@ 202207L // also in \libheader{ranges}
#define @\defnlibxname{cpp_lib_ranges_as_rvalue}@ 202207L // also in \libheader{ranges}
Expand Down