diff --git a/source/ranges.tex b/source/ranges.tex index 987ce3d95e..42bd183851 100644 --- a/source/ranges.tex +++ b/source/ranges.tex @@ -187,6 +187,25 @@ template class C, class... Args> constexpr auto to(Args&&... args); + // \ref{range.any}, any view + enum class any_view_options : uint_least32_t; + + constexpr bool + @\exposid{any-view-flag-is-set}@(any_view_options opts, any_view_options flag); // \expos + + template + class any_view; + + template + constexpr bool + enable_borrowed_range> = + @\exposid{any-view-flag-is-set}@(Opts, any_view_options::borrowed); + // \ref{range.empty}, empty view template requires is_object_v @@ -2607,6 +2626,909 @@ \end{itemize} \end{itemdescr} +\rSec2[range.any]{Any view} + +\rSec3[range.any.general]{General} + +\pnum +The \tcode{any_view} class is a wrapper that can store, move, and traverse an arbitrary object that models \tcode{view}. +The wrapped object is referred to as the \defnx{target view object}[object!view!target]. + +\pnum +A program that instantiates a specialization of \tcode{any_view} is ill-formed unless all the following are true: +\begin{itemize} +\item +\tcode{Element} is an object type. + +\item +\tcode{\exposid{any-view-flag-is-set}(Opts, any_view_options::input)} is \tcode{true}. + +\item +\tcode{common_reference_with\&>} is modeled. + +\item +\tcode{common_reference_with\&>} is modeled. + +\item +\tcode{@\exposid{is-signed-integer-like}@} is \tcode{true}, +and \tcode{same_as>} is \tcode{true}. + +\item +If \tcode{@\exposid{any-view-flag-is-set}@(Opts, any_view_options::contiguous)} is \tcode{true}, +both of the following are true: +\begin{itemize} +\item +\tcode{same_as} is \tcode{true}. + +\item +\tcode{same_as} is \tcode{true}. +\end{itemize} +\end{itemize} + +\pnum +\begin{note} +These rules ensure that \tcode{any_view::iterator} models \tcode{indirectly_readable}. +\end{note} + +\pnum +Recommended practice: +Implementations should avoid the use of dynamically allocated memory for a small target view object of type \tcode{T} +which satisfies \tcode{is_nothrow_move_constructible_v}. + +\pnum +An \tcode{any_view::iterator} object holds an iterator object obtained from a target view object referred to as the +\defnx{target iterator}[iterator!target] object. +It may also hold a sentinel object obtained from a target view object referred to as the \defnx{target sentinel object}[object!sentinel!target]. +When an \tcode{any_view::iterator} object holds a target iterator object and a target sentinel object, +it is said to be \defnx{self contained}[contained!self]. +An \tcode{any_view::sentinel} object may hold a target sentinel object. + +\rSec3[range.any.options]{Enum class \tcode{any_view_options}} + +\pnum +The enum class type \tcode{any_view_options} is a bitmask type\iref{bitmask.types} that specifies bitmask constants used to control +the concepts that \tcode{any_view} models, with the meanings listed in~\tref{range.any.options}. + +\begin{floattable} +{Enum class \tcode{any_view_options}}{range.any.options}{lrl} +\topline +\chdr{Name} & \chdr{Value} & \chdr{Concept} \\ \capsep + +\tcode{input} & \tcode{1} & \tcode{input_range} \\ \rowsep +\tcode{forward} & \tcode{3} & \tcode{forward_range} \\ \rowsep +\tcode{bidirectional} & \tcode{7} & \tcode{bidirectional_range} \\ \rowsep +\tcode{random_access} & \tcode{15} & \tcode{random_access_range} \\ \rowsep +\tcode{contiguous} & \tcode{31} & \tcode{contiguous_range} \\ \rowsep +\tcode{approximately_sized} & \tcode{32} & \tcode{approximately_sized_range} \\ \rowsep +\tcode{sized} & \tcode{96} & \tcode{sized_range} \\ \rowsep +\tcode{borrowed} & \tcode{128} & \tcode{borrowed_range} \\ \rowsep +\tcode{copyable} & \tcode{256} & \tcode{copyable} \\ +\end{floattable} + +\rSec3[range.any.class]{Class template \tcode{any_view}} + +\indexlibraryglobal{any_view}% +\begin{codeblock} +namespace std::ranges { + template + class any_view : public view_interface> { + class @\exposid{iterator}@; // \expos + class @\exposid{sentinel}@; // \expos + public: + // \ref{range.any.ctor}, constructors, assignment, and destructor + constexpr any_view() noexcept; + template constexpr any_view(Rng&& rng); + constexpr any_view(const any_view&); + constexpr any_view(any_view&&) noexcept; + + constexpr any_view& operator=(const any_view&); + constexpr any_view& operator=(any_view&&) noexcept; + + constexpr ~any_view(); + + // \ref{range.any.access}, range access + constexpr @\exposid{iterator}@ begin(); + constexpr @\exposid{sentinel}@ end(); + + constexpr @\exposid{make-unsigned-like-t}@ size(); + constexpr @\exposid{make-unsigned-like-t}@ reserve_hint(); + + // \ref{range.any.swap}, swap + constexpr void swap(any_view&) noexcept; + constexpr friend void swap(any_view&, any_view&) noexcept; + }; +} +\end{codeblock} + +\pnum +The default argument for the template parameter \tcode{RValueRef} is +\tcode{remove_reference_t\&\&} if \tcode{is_lvalue_reference_v} is \tcode{true}, +and \tcode{Ref} otherwise. + +\begin{itemdecl} +constexpr bool @\exposid{any-view-flag-is-set}@(any_view_options opts, any_view_options flag); // \expos +\end{itemdecl} + +\begin{itemdescr} +\pnum +\returns +\tcode{(opts \& flag) == flag} +\end{itemdescr} + +\rSec3[range.any.ctor]{Constructors, assignment, and destructor} + +\begin{itemdecl} +constexpr any_view() noexcept; +\end{itemdecl} + +\begin{itemdescr} +\pnum +\ensures +\tcode{*this} holds a target view object \tcode{v}, where \tcode{ranges::empty(v)} is \tcode{true}. +\end{itemdescr} + +\begin{itemdecl} +template constexpr any_view(Rng&& rng); +\end{itemdecl} + +\begin{itemdescr} +\pnum +\constraints +\begin{itemize} +\item +For every bitmask constant \tcode{c} listed in \tref{range.any.options} except for \tcode{copyable}, +if \tcode{\exposid{any-view-flag-is-set}\allowbreak(Opts, c)} is \tcode{true}, +\tcode{Rng} models the corresponding concept, + +\item +\tcode{remove_cvref_t} is not the same type as \tcode{any_view}, + +\item +\tcode{is_convertible_v, Ref>} is \tcode{true}, + +\item +\tcode{is_convertible_v, RValueRef>} is \tcode{true}, + +\item +the width of the type \tcode{range_difference_t} is not greater than the width of the type \tcode{Diff}, + +\item +if \tcode{\exposid{any-view-flag-is-set}(Opts, any_view_options::contig\-uous)} is \tcode{true}, +\tcode{\exposid{uses-non\-quali\-fication-pointer-conver\-sion}>,\\ add_pointer_t>} is \tcode{false}, + +\item +let \tcode{R} be \tcode{remove_cvref_t}, +if \tcode{\exposid{any-view-flag-is-set}(Opts, any_view_options::borrow\-ed)} is \tcode{true} +and \tcode{enable_view} is \tcode{true}, \tcode{borrowed_range} is \tcode{true}, + +\item +\tcode{reference_converts_from_temporary_v>} is \tcode{false}, and + +\item +\tcode{reference_converts_from_temporary_v>}\\ +is \tcode{false}. +\end{itemize} + +\pnum +\mandates +\begin{itemize} +\item +\tcode{Rng} models \tcode{viewable_range}, and + +\item +either \tcode{\exposid{any-view-flag-is-set}(Opts, any_view_options::copyable)} is \tcode{false}, +or \tcode{all_t} models \tcode{copyable}. +\end{itemize} + +\pnum +\ensures +\begin{itemize} +\item +If \tcode{remove_cvref_t} is a specialization \tcode{any_view}, +\tcode{Ref} and \tcode{Ref2} are similar types, \tcode{RValueRef} and \tcode{RValueRef2} are similar types, +and \tcode{Diff} and \tcode{Diff2} are the same type, +\tcode{*this} has a target view object direct-non-list-initialized with the target view object of +\tcode{std::forward(rng)}, + +\item +otherwise, \tcode{*this} has a target view object of type \tcode{all_t} direct-non-list-initialized with +\tcode{std::forward(rng)}. +\end{itemize} + +\pnum +\throws +Any exception thrown by the initialization of the target view object. +May throw \tcode{bad_alloc}. +\end{itemdescr} + +\begin{itemdecl} +constexpr any_view(const any_view& other); +\end{itemdecl} + +\begin{itemdescr} +\pnum +\constraints +\tcode{\exposid{any-view-flag-is-set}(Opts, any_view_options::copyable)} is \tcode{true}. + +\pnum +\ensures +The target view object of \tcode{*this} is a copy of the target view object of \tcode{other}. +\end{itemdescr} + +\begin{itemdecl} +constexpr any_view(any_view&& other) noexcept; +\end{itemdecl} + +\begin{itemdescr} +\pnum +\ensures +The target view object of \tcode{*this} is equivalent to the target view object of \tcode{other} +before the construction of \tcode{*this}, and \tcode{other} holds a target view object \tcode{v} +where \tcode{ranges::empty(v)} is \tcode{true}. +\end{itemdescr} + +\begin{itemdecl} +constexpr any_view& operator=(const any_view& other); +\end{itemdecl} + +\begin{itemdescr} +\pnum +\constraints +\tcode{\exposid{any-view-flag-is-set}(Opts, any_view_options::copyable)} is \tcode{true}. + +\pnum +\effects +Equivalent to: \tcode{any_view(other).swap(*this);}. + +\pnum +\returns +\tcode{*this}. +\end{itemdescr} + +\begin{itemdecl} +constexpr any_view& operator=(any_view&& other) noexcept; +\end{itemdecl} + +\begin{itemdescr} +\pnum +\effects +Equivalent to: \tcode{any_view(std::move(other)).swap(*this);}. + +\pnum +\returns +\tcode{*this}. +\end{itemdescr} + +\begin{itemdecl} +constexpr ~any_view(); +\end{itemdecl} + +\begin{itemdescr} +\pnum +\effects +Destroys the target view object of \tcode{*this}. +\end{itemdescr} + +\rSec3[range.any.access]{Range access} + +\begin{itemdecl} +constexpr @\exposid{iterator}@ begin(); +\end{itemdecl} + +\begin{itemdescr} +\pnum +\effects +Let \tcode{v} be an lvalue designating the target view object of \tcode{*this}, +returns an object \tcode{o} that holds a target iterator object direct-non-list-initialized with +\tcode{ranges::begin(v)} and if \tcode{o} is self contained, +\tcode{o} holds a target sentinel object direct-non-list-initialized with \tcode{ranges::end(v)}. +\end{itemdescr} + +\begin{itemdecl} +constexpr @\exposid{sentinel}@ end(); +\end{itemdecl} + +\begin{itemdescr} +\pnum +\effects +Let \tcode{v} be an lvalue designating the target view object of \tcode{*this}, +returns an object that holds a target sentinel object direct-non-list-initialized with \tcode{ranges::end(v)}, +if an iterator returned by \tcode{begin} is not self contained. +Otherwise, returns an object that does not hold a target sentinel object. +\begin{note} +A \exposid{sentinel} that does not hold a target sentinel object can be a distinct value from a value-initialized sentinel. +\end{note} +\end{itemdescr} + +\begin{itemdecl} +constexpr @\exposid{make-unsigned-like-t}@ size(); +\end{itemdecl} + +\begin{itemdescr} +\pnum +\constraints +\tcode{\exposid{any-view-flag-is-set}(Opts, any_view_options::sized)} is \tcode{true}. + +\pnum +\returns +\tcode{@\exposid{make-unsigned-like-t}@(ranges::size(v))}, +where \tcode{v} is an lvalue designating the target view object of \tcode{*this}. +\end{itemdescr} + +\begin{itemdecl} +constexpr @\exposid{make-unsigned-like-t}@ reserve_hint(); +\end{itemdecl} + +\begin{itemdescr} +\pnum +\constraints +\tcode{\exposid{any-view-flag-is-set}(Opts, any_view_options::approximately_sized)} is \tcode{true}. + +\pnum +\returns +\tcode{\exposid{make-unsigned-like-t}(ranges::reserve_hint(v))}, +where \tcode{v} is an lvalue designating the target view object of \tcode{*this}. +\end{itemdescr} + +\rSec3[range.any.swap]{Swap} + +\begin{itemdecl} +constexpr void swap(any_view& other) noexcept; +\end{itemdecl} + +\begin{itemdescr} +\pnum +\effects +Exchanges the target view objects of \tcode{*this} and \tcode{other}. +\end{itemdescr} + +\begin{itemdecl} +constexpr friend void swap(any_view& lhs, any_view& rhs) noexcept; +\end{itemdecl} + +\begin{itemdescr} +\pnum +\effects +Equivalent to: \tcode{lhs.swap(rhs)}. +\end{itemdescr} + +\rSec3[range.any.iterator]{Class \tcode{any_view::iterator}} + +\indexlibraryglobal{any_view::\exposid{iterator}}% +\begin{codeblock} +namespace std::ranges { + template + class any_view::iterator { + public: + using iterator_concept = @\seebelow@; + using iterator_category = @\seebelow@; // not always present + using value_type = remove_cv_t; + using difference_type = Diff; + + constexpr @\exposid{iterator}@() noexcept; + + constexpr Ref operator*() const; + + constexpr @\exposid{iterator}@& operator++(); + constexpr void operator++(int); + constexpr @\exposid{iterator}@ operator++(int) + requires (@\exposid{any-view-flag-is-set}@(Opts, any_view_options::forward)) = default; + + constexpr @\exposid{iterator}@& operator--(); + constexpr @\exposid{iterator}@ operator--(int) + requires (@\exposid{any-view-flag-is-set}@(Opts, any_view_options::bidirectional)) = default; + + constexpr @\exposid{iterator}@& operator+=(difference_type n); + constexpr @\exposid{iterator}@& operator-=(difference_type n); + + constexpr Ref operator[](difference_type n) const; + constexpr add_pointer_t operator->() const; + + friend constexpr bool operator==(const @\exposid{iterator}@& x, const @\exposid{iterator}@& y); + + friend constexpr bool operator<(const @\exposid{iterator}@& x, const @\exposid{iterator}@& y); + friend constexpr bool operator>(const @\exposid{iterator}@& x, const @\exposid{iterator}@& y); + friend constexpr bool operator<=(const @\exposid{iterator}@& x, const @\exposid{iterator}@& y); + friend constexpr bool operator>=(const @\exposid{iterator}@& x, const @\exposid{iterator}@& y); + + friend constexpr strong_ordering operator<=>(const @\exposid{iterator}@& x, const @\exposid{iterator}@& y); + + friend constexpr @\exposid{iterator}@ operator+(const @\exposid{iterator}@& i, difference_type n); + friend constexpr @\exposid{iterator}@ operator+(difference_type n, const @\exposid{iterator}@& i); + + friend constexpr @\exposid{iterator}@ operator-(const @\exposid{iterator}@& i, difference_type n); + friend constexpr difference_type operator-(const @\exposid{iterator}@& x, const @\exposid{iterator}@& y); + + friend constexpr RValueRef iter_move(const @\exposid{iterator}@& iter); + + }; +} +\end{codeblock} + +\pnum +\tcode{\exposid{iterator}::iterator_concept} is defined as follows: +\begin{itemize} +\item +If \tcode{\exposid{any-view-flag-is-set}(Opts, any_view_options::contiguous)} is \tcode{true}, +then \tcode{iterator_conce\-pt} denotes \tcode{contiguous_iterator_tag}. + +\item +Otherwise, if \tcode{\exposid{any-view-flag-is-set}(Opts, any_view_options::random_access)} is \tcode{true}, +then \tcode{iterat\-or_concept} denotes \tcode{random_access_iterator_tag}. + +\item +Otherwise, if \tcode{\exposid{any-view-flag-is-set}(Opts, any_view_options::bidirectional)} is \tcode{true}, +then \tcode{iterator_concept} denotes \tcode{bidirectional_iterator_tag}. + +\item +Otherwise, if \tcode{\exposid{any-view-flag-is-set}(Opts, any_view_options::for\-ward)} is \tcode{true}, +then \tcode{iterator\-_concept} denotes \tcode{forward_iterator_tag}. + +\item +Otherwise, \tcode{iterator_concept} denotes \tcode{input_iterator_tag}. +\end{itemize} + +\pnum +The member typedef-name \tcode{iterator_category} is defined if and only if +\tcode{\exposid{any-view-flag-is-set}(Opts, any_view_options::forward)} is \tcode{true}. +In that case, \tcode{\exposid{iterator}::iterator_category} is defined as follows: +\begin{itemize} +\item +If \tcode{iterator_concept} is \tcode{contiguous_iterator_tag}, then \tcode{iterator_category} denotes \tcode{random_ac\-cess_iterator_tag}. + +\item +Otherwise, if \tcode{is_reference_v} is \tcode{true}, then \tcode{iterator_category} denotes \tcode{iterator_concept}. + +\item +Otherwise, \tcode{iterator_category} denotes \tcode{input_iterator_tag}. +\end{itemize} + +\begin{itemdecl} +constexpr @\exposid{iterator}@() noexcept; +\end{itemdecl} + +\begin{itemdescr} +\pnum +\constraints +\tcode{\exposid{any-view-flag-is-set}(Opts, any_view_options::forward)} is \tcode{true}. + +\pnum +\ensures +\tcode{*this} holds no target iterator object. +\end{itemdescr} + +\begin{itemdecl} +constexpr Ref operator*() const; +\end{itemdecl} + +\begin{itemdescr} +\pnum +\expects +\tcode{*this} holds a target iterator object. + +\pnum +\returns +\tcode{static_cast(*it)}, where \tcode{it} is an lvalue designating the target iterator object of \tcode{*this}. +\end{itemdescr} + +\begin{itemdecl} +constexpr @\exposid{iterator}@& operator++(); +\end{itemdecl} + +\begin{itemdescr} +\pnum +\expects +\tcode{*this} holds a target iterator object. + +\pnum +\effects +Equivalent to: +\begin{codeblock} +++it; +return *this; +\end{codeblock} +where \tcode{it} is an lvalue designating the target iterator object of \tcode{*this}. +\end{itemdescr} + +\begin{itemdecl} +constexpr void operator++(int); +\end{itemdecl} + +\begin{itemdescr} +\pnum +\effects +Equivalent to: \tcode{++*this;}. +\end{itemdescr} + +\begin{itemdecl} +constexpr @\exposid{iterator}@& operator--(); +\end{itemdecl} + +\begin{itemdescr} +\pnum +\constraints +\tcode{\exposid{any-view-flag-is-set}(Opts, any_view_options::bidirectional)} is \tcode{true}. + +\pnum +\expects +\tcode{*this} holds a target iterator object. + +\pnum +\effects +Equivalent to: +\begin{codeblock} +--it; +return *this; +\end{codeblock} +where \tcode{it} is an lvalue designating the target iterator object of \tcode{*this}. +\end{itemdescr} + +\begin{itemdecl} +constexpr @\exposid{iterator}@& operator+=(difference_type n); +\end{itemdecl} + +\begin{itemdescr} +\pnum +\constraints +\tcode{\exposid{any-view-flag-is-set}(Opts, any_view_options::random_access)} is \tcode{true}. + +\pnum +\expects +\tcode{*this} holds a target iterator object, and let \tcode{I} be the type of the target iterator object +and \tcode{D} be \tcode{iter_difference_t}, \tcode{in_range(n)} is \tcode{true}. + +\pnum +\effects +Equivalent to: +\begin{codeblock} +it += static_cast(n); +return *this; +\end{codeblock} +where \tcode{it} is an lvalue designating the target iterator object of \tcode{*this}, +and \tcode{D} is \allowbreak\tcode{iter_difference_t>}. +\end{itemdescr} + +\begin{itemdecl} +constexpr @\exposid{iterator}@& operator-=(difference_type n); +\end{itemdecl} + +\begin{itemdescr} +\pnum +\constraints +\tcode{\exposid{any-view-flag-is-set}(Opts, any_view_options::random_access)} is \tcode{true}. + +\pnum +\expects +\tcode{*this} holds a target iterator object, and let \tcode{I} be the type of the target iterator object +and \tcode{D} be \tcode{iter_difference_t}, \tcode{in_range(n)} is \tcode{true}. + +\pnum +\effects +Equivalent to: +\begin{codeblock} +it -= static_cast(n); +return *this; +\end{codeblock} +where \tcode{it} is an lvalue designating the target iterator object of \tcode{*this}, +and \tcode{D} is \allowbreak\tcode{iter_difference_t>}. +\end{itemdescr} + +\begin{itemdecl} +constexpr Ref operator[](difference_type n) const; +\end{itemdecl} + +\begin{itemdescr} +\pnum +\constraints +\tcode{\exposid{any-view-flag-is-set}(Opts, any_view_options::random_access)} is \tcode{true}. + +\pnum +\effect +Equivalent to: +\begin{codeblock} +return *(*this + n); +\end{codeblock} +\end{itemdescr} + +\begin{itemdecl} +constexpr add_pointer_t operator->() const; +\end{itemdecl} + +\begin{itemdescr} +\pnum +\constraints +\tcode{\exposid{any-view-flag-is-set}(Opts, any_view_options::contiguous)} is \tcode{true}. + +\pnum +\expects +\tcode{*this} holds a target iterator object. + +\pnum +\returns +\tcode{to_address(it)}, where \tcode{it} is an lvalue designating the target iterator object of \tcode{*this}. +\end{itemdescr} + +\begin{itemdecl} +friend constexpr bool operator==(const @\exposid{iterator}@& x, const @\exposid{iterator}@& y); +\end{itemdecl} + +\begin{itemdescr} +\pnum +\constraints +\tcode{\exposid{any-view-flag-is-set}(Opts, any_view_options::forward)} is \tcode{true}. + +\pnum +\effects +\begin{itemize} +\item +If \tcode{x} and \tcode{y} hold target iterator objects of the same type, equivalent to +\begin{codeblock} +return it1 == it2; +\end{codeblock} +where \tcode{it1} and \tcode{it2} designate the target iterator objects of \tcode{x} and \tcode{y} respectively. + +\item +Otherwise, if neither \tcode{x} nor \tcode{y} holds a target iterator object, equivalent to: +\begin{codeblock} +return true; +\end{codeblock} + +\item +Otherwise, equivalent to: +\begin{codeblock} +return false; +\end{codeblock} +\end{itemize} +\end{itemdescr} + +\begin{itemdecl} +friend constexpr bool operator<(const @\exposid{iterator}@& x, const @\exposid{iterator}@& y); +friend constexpr bool operator>(const @\exposid{iterator}@& x, const @\exposid{iterator}@& y); +friend constexpr bool operator<=(const @\exposid{iterator}@& x, const @\exposid{iterator}@& y); +friend constexpr bool operator>=(const @\exposid{iterator}@& x, const @\exposid{iterator}@& y); +\end{itemdecl} + +\begin{itemdescr} +\pnum +\constraints +\tcode{\exposid{any-view-flag-is-set}(Opts, any_view_options::random_access)} is \tcode{true}. + +\pnum +Let \exposid{op} be the operator. + +\pnum +\effects +\begin{itemize} +\item +If \tcode{x} and \tcode{y} hold target iterator objects of the same type, equivalent to: +\begin{codeblock} +return it1 @\exposid{op}@ it2; +\end{codeblock} +where \tcode{it1} and \tcode{it2} designate the target iterator objects of \tcode{x} and \tcode{y} respectively. + +\item +Otherwise, if both \tcode{x} and \tcode{y} hold no target iterator object, equivalent to: +\begin{codeblock} +return 0 @\exposid{op}@ 0; +\end{codeblock} + +\item +Otherwise, the behavior is erroneous and the return value is unspecified. +\end{itemize} +\end{itemdescr} + +\begin{itemdecl} +friend constexpr strong_ordering operator<=>(const @\exposid{iterator}@& x, const @\exposid{iterator}@& y); +\end{itemdecl} + +\begin{itemdescr} +\pnum +\constraints +\tcode{\exposid{any-view-flag-is-set}(Opts, any_view_options::random_access)} is \tcode{true}. + +\pnum +\effects +\begin{itemize} +\item +If \tcode{x} and \tcode{y} hold target iterator objects of the same type, equivalent to: +\begin{codeblock} +if constexpr (@\libconcept{three_way_comparable}@) { + return it1 <=> it2; +} else { + if (it1 < it2) return strong_ordering::less; + if (it2 < it1) return strong_ordering::greater; + return strong_ordering::equal; +} +\end{codeblock} +where \tcode{it1} and \tcode{it2} designate the target iterator objects of \tcode{x} and \tcode{y} respectively, +and \tcode{It} is \tcode{remove_cvref_t}. + +\item +Otherwise, if both \tcode{x} and \tcode{y} hold no target iterator object, equivalent to: +\begin{codeblock} +return strong_ordering::equal; +\end{codeblock} + +\item +Otherwise, the behavior is erroneous and the return value is unspecified. +\end{itemize} +\end{itemdescr} + +\begin{itemdecl} +friend constexpr @\exposid{iterator}@ operator+(const @\exposid{iterator}@& i, difference_type n); +\end{itemdecl} + +\begin{itemdescr} +\pnum +\constraints +\tcode{\exposid{any-view-flag-is-set}(Opts, any_view_options::random_access)} is \tcode{true}. + +\pnum +\effects +Equivalent to: +\begin{codeblock} +auto temp = i; +temp += n; +return temp; +\end{codeblock} +\end{itemdescr} + +\begin{itemdecl} +friend constexpr @\exposid{iterator}@ operator+(difference_type n, const @\exposid{iterator}@& i); +\end{itemdecl} + +\begin{itemdescr} +\pnum +\constraints +\tcode{\exposid{any-view-flag-is-set}(Opts, any_view_options::random_access)} is \tcode{true}. + +\pnum +\effects +Equivalent to: +\begin{codeblock} +return i + n; +\end{codeblock} +\end{itemdescr} + +\begin{itemdecl} +friend constexpr @\exposid{iterator}@ operator-(const @\exposid{iterator}@& i, difference_type n); +\end{itemdecl} + +\begin{itemdescr} +\pnum +\constraints +\tcode{\exposid{any-view-flag-is-set}(Opts, any_view_options::random_access)} is \tcode{true}. + +\pnum +\effects +Equivalent to: +\begin{codeblock} +auto temp = i; +temp -= n; +return temp; +\end{codeblock} +\end{itemdescr} + +\begin{itemdecl} +friend constexpr difference_type operator-(const @\exposid{iterator}@& x, const @\exposid{iterator}@& y); +\end{itemdecl} + +\begin{itemdescr} +\pnum +\constraints +\tcode{\exposid{any-view-flag-is-set}(Opts, any_view_options::random_access)} is \tcode{true}. + +\pnum +\effects +\begin{itemize} +\item +If \tcode{x} and \tcode{y} hold target iterator objects of the same type, equivalent to: +\begin{codeblock} +return it1 - it2; +\end{codeblock} +where \tcode{it1} and \tcode{it2} designate the target iterator objects of \tcode{x} and \tcode{y} respectively. + +\item +Otherwise, if both \tcode{x} and \tcode{y} hold no target iterator object, equivalent to: +\begin{codeblock} +return 0; +\end{codeblock} + +\item +Otherwise, the behavior is erroneous and the return value is unspecified. +\end{itemize} +\end{itemdescr} + +\begin{itemdecl} +friend constexpr RValueRef iter_move(const @\exposid{iterator}@& iter); +\end{itemdecl} + +\begin{itemdescr} +\pnum +\expects +\tcode{iter} holds a target iterator object. + +\pnum +\returns +\tcode{static_cast(ranges::iter_move(it))}, +where \tcode{it} is an lvalue designating the target iterator object of \tcode{iter}. +\end{itemdescr} + +\rSec3[range.any.sentinel]{Class \tcode{any_view::sentinel}} + +\indexlibraryglobal{any_view::\exposid{sentinel}}% +\begin{codeblock} +namespace std::ranges { + template + class any_view::@\exposid{sentinel}@ { + public: + constexpr sentinel() noexcept; + + friend constexpr bool operator==(const @\exposid{iterator}@& x, const @\exposid{sentinel}@& y); + + }; +} +\end{codeblock} + +\begin{itemdecl} +constexpr @\exposid{sentinel}@() noexcept; +\end{itemdecl} + +\begin{itemdescr} +\pnum +\ensures +\tcode{*this} holds no target sentinel object. +\end{itemdescr} + +\begin{itemdecl} +friend constexpr bool operator==(const @\exposid{iterator}@& x, const @\exposid{sentinel}@& y); +\end{itemdecl} + +\begin{itemdescr} +\pnum +\effects +\begin{itemize} +\item +If both \tcode{x} and \tcode{y} hold a target sentinel object, the behavior is erroneous and the return value is unspecified. + +\item +Otherwise, if \tcode{x} holds a target iterator object, +either \tcode{x} or \tcode{y} holds a target sentinel object, +and the target iterator object and the target sentinel object were obtained from the same range, equivalent to: +\begin{codeblock} +return it == st; +\end{codeblock} +where \tcode{it} designates the target iterator object of \tcode{x} and \tcode{st} designates the target sentinel object of +\tcode{x} if \tcode{x} is self contained, or the target sentinel object of \tcode{y} otherwise. + +\item +Otherwise, if \tcode{x} holds no target iterator object, +and both \tcode{x} and \tcode{y} hold no target sentinel object, equivalent to: +\begin{codeblock} +return true; +\end{codeblock} + +\item +Otherwise, if either \tcode{x} holds no target iterator object or \tcode{y} holds no target sentinel object, +the behavior is erroneous and the return value is unspecified. + +\item +Otherwise, the behavior is undefined +\end{itemize} +\end{itemdescr} + \rSec1[range.factories]{Range factories} \rSec2[range.factories.general]{General} diff --git a/source/support.tex b/source/support.tex index 759c5fe3d2..34615df2b5 100644 --- a/source/support.tex +++ b/source/support.tex @@ -532,6 +532,7 @@ // freestanding, also in \libheader{memory}, \libheader{scoped_allocator}, \libheader{string}, \libheader{deque}, \libheader{forward_list}, \libheader{list}, // \libheader{vector}, \libheader{map}, \libheader{set}, \libheader{unordered_map}, \libheader{unordered_set} #define @\defnlibxname{cpp_lib_any}@ 201606L // also in \libheader{any} +#define @\defnlibxname{cpp_lib_any_view}@ 202611L // also in \libheader{ranges} #define @\defnlibxname{cpp_lib_apply}@ 202603L // freestanding, also in \libheader{tuple}, \libheader{type_traits}, \libheader{meta} #define @\defnlibxname{cpp_lib_array_constexpr}@ 201811L