diff --git a/source/support.tex b/source/support.tex index f7a76d7893..104c414a58 100644 --- a/source/support.tex +++ b/source/support.tex @@ -726,6 +726,7 @@ #define @\defnlibxname{cpp_lib_not_fn}@ 202306L // freestanding, also in \libheader{functional} #define @\defnlibxname{cpp_lib_null_iterators}@ 201304L // freestanding, also in \libheader{iterator} #define @\defnlibxname{cpp_lib_optional}@ 202110L // also in \libheader{optional} +#define @\defnlibxname{cpp_lib_optional_range_support}@ 202406L // freestanding, also in \libheader{optional} #define @\defnlibxname{cpp_lib_out_ptr}@ 202311L // freestanding, also in \libheader{memory} #define @\defnlibxname{cpp_lib_parallel_algorithm}@ 201603L // also in \libheader{algorithm}, \libheader{numeric} #define @\defnlibxname{cpp_lib_polymorphic_allocator}@ 201902L // also in \libheader{memory_resource} diff --git a/source/utilities.tex b/source/utilities.tex index 335b85035a..fcbb038a43 100644 --- a/source/utilities.tex +++ b/source/utilities.tex @@ -3168,6 +3168,11 @@ template class optional; // partially freestanding + template + constexpr bool ranges::enable_view> = true; + template + constexpr auto format_kind> = range_format::disabled; + template concept @\defexposconcept{is-derived-from-optional}@ = requires(const T& t) { // \expos [](const optional&){ }(t); @@ -3248,7 +3253,9 @@ template class optional { public: - using value_type = T; + using value_type = T; + using iterator = @\impdefnc@; // see~\ref{optional.iterators} + using const_iterator = @\impdefnc@; // see~\ref{optional.iterators} // \ref{optional.ctor}, constructors constexpr optional() noexcept; @@ -3282,6 +3289,12 @@ // \ref{optional.swap}, swap constexpr void swap(optional&) noexcept(@\seebelow@); + // \ref{optional.iterators}, iterator support + constexpr iterator begin() noexcept; + constexpr const_iterator begin() const noexcept; + constexpr iterator end() noexcept; + constexpr const_iterator end() const noexcept; + // \ref{optional.observe}, observers constexpr const T* operator->() const noexcept; constexpr T* operator->() noexcept; @@ -4001,6 +4014,59 @@ the state of \tcode{*val} and \tcode{*rhs.val} is determined by the exception safety guarantee of \tcode{T}'s move constructor. \end{itemdescr} +\rSec3[optional.iterators]{Iterator support} + +\indexlibrarymember{iterator}{optional}% +\indexlibrarymember{const_iterator}{optional}% +\begin{itemdecl} +using iterator = @\impdef@; +using const_iterator = @\impdef@; +\end{itemdecl} + +\begin{itemdescr} +\pnum +These types +model \libconcept{contiguous_iterator}\iref{iterator.concept.contiguous}, +meet the \oldconcept{RandomAccessIterator} requirements\iref{random.access.iterators}, and +meet the requirements for constexpr iterators\iref{iterator.requirements.general}, +with value type \tcode{remove_cv_t}. +The reference type is \tcode{T\&} for \tcode{iterator} and +\tcode{const T\&} for \tcode{const_iterator}. + +\pnum +All requirements on container iterators\iref{container.reqmts} apply to +\tcode{optional::iterator} and \tcode{optional::\linebreak{}const_iterator} as well. + +\pnum +Any operation that initializes or destroys the contained value of an optional object invalidates all iterators into that object. +\end{itemdescr} + +\indexlibrarymember{begin}{optional}% +\begin{itemdecl} +constexpr iterator begin() noexcept; +constexpr const_iterator begin() const noexcept; +\end{itemdecl} + +\begin{itemdescr} +\pnum +\returns +If \tcode{has_value()} is \tcode{true}, +an iterator referring to the contained value. +Otherwise, a past-the-end iterator value. +\end{itemdescr} + +\indexlibrarymember{end}{optional}% +\begin{itemdecl} +constexpr iterator end() noexcept; +constexpr const_iterator end() const noexcept; +\end{itemdecl} + +\begin{itemdescr} +\pnum +\returns +\tcode{begin() + has_value()}. +\end{itemdescr} + \rSec3[optional.observe]{Observers} \indexlibrarymember{operator->}{optional}%