|
3168 | 3168 | template<class T>
|
3169 | 3169 | class optional; // partially freestanding
|
3170 | 3170 |
|
| 3171 | + template<class T> |
| 3172 | + constexpr bool ranges::enable_view<optional<T>> = true; |
| 3173 | + template<class T> |
| 3174 | + constexpr auto format_kind<optional<T>> = range_format::disabled; |
| 3175 | + |
3171 | 3176 | template<class T>
|
3172 | 3177 | concept @\defexposconcept{is-derived-from-optional}@ = requires(const T& t) { // \expos
|
3173 | 3178 | []<class U>(const optional<U>&){ }(t);
|
|
3248 | 3253 | template<class T>
|
3249 | 3254 | class optional {
|
3250 | 3255 | public:
|
3251 |
| - using value_type = T; |
| 3256 | + using value_type = T; |
| 3257 | + using iterator = @\impdefnc@; // see~\ref{optional.iterators} |
| 3258 | + using const_iterator = @\impdefnc@; // see~\ref{optional.iterators} |
3252 | 3259 |
|
3253 | 3260 | // \ref{optional.ctor}, constructors
|
3254 | 3261 | constexpr optional() noexcept;
|
|
3282 | 3289 | // \ref{optional.swap}, swap
|
3283 | 3290 | constexpr void swap(optional&) noexcept(@\seebelow@);
|
3284 | 3291 |
|
| 3292 | + // \ref{optional.iterators}, iterator support |
| 3293 | + constexpr iterator begin() noexcept; |
| 3294 | + constexpr const_iterator begin() const noexcept; |
| 3295 | + constexpr iterator end() noexcept; |
| 3296 | + constexpr const_iterator end() const noexcept; |
| 3297 | + |
3285 | 3298 | // \ref{optional.observe}, observers
|
3286 | 3299 | constexpr const T* operator->() const noexcept;
|
3287 | 3300 | constexpr T* operator->() noexcept;
|
|
4001 | 4014 | the state of \tcode{*val} and \tcode{*rhs.val} is determined by the exception safety guarantee of \tcode{T}'s move constructor.
|
4002 | 4015 | \end{itemdescr}
|
4003 | 4016 |
|
| 4017 | +\rSec3[optional.iterators]{Iterator support} |
| 4018 | + |
| 4019 | +\indexlibrarymember{iterator}{optional}% |
| 4020 | +\indexlibrarymember{const_iterator}{optional}% |
| 4021 | +\begin{itemdecl} |
| 4022 | +using iterator = @\impdef@; |
| 4023 | +using const_iterator = @\impdef@; |
| 4024 | +\end{itemdecl} |
| 4025 | + |
| 4026 | +\begin{itemdescr} |
| 4027 | +\pnum |
| 4028 | +These types |
| 4029 | +model \libconcept{contiguous_iterator}\iref{iterator.concept.contiguous}, |
| 4030 | +meet the \oldconcept{RandomAccessIterator} requirements\iref{random.access.iterators}, and |
| 4031 | +meet the requirements for constexpr iterators\iref{iterator.requirements.general}, |
| 4032 | +with value type \tcode{remove_cv_t<T>}. |
| 4033 | +The reference type is \tcode{T\&} for \tcode{iterator} and |
| 4034 | +\tcode{const T\&} for \tcode{const_iterator}. |
| 4035 | + |
| 4036 | +\pnum |
| 4037 | +All requirements on container iterators\iref{container.reqmts} apply to |
| 4038 | +\tcode{optional::iterator} and \tcode{optional::\linebreak{}const_iterator} as well. |
| 4039 | + |
| 4040 | +\pnum |
| 4041 | +Any operation that initializes or destroys the contained value of an optional object invalidates all iterators into that object. |
| 4042 | +\end{itemdescr} |
| 4043 | + |
| 4044 | +\indexlibrarymember{begin}{optional}% |
| 4045 | +\begin{itemdecl} |
| 4046 | +constexpr iterator begin() noexcept; |
| 4047 | +constexpr const_iterator begin() const noexcept; |
| 4048 | +\end{itemdecl} |
| 4049 | + |
| 4050 | +\begin{itemdescr} |
| 4051 | +\pnum |
| 4052 | +\returns |
| 4053 | +If \tcode{has_value()} is \tcode{true}, |
| 4054 | +an iterator referring to the contained value. |
| 4055 | +Otherwise, a past-the-end iterator value. |
| 4056 | +\end{itemdescr} |
| 4057 | + |
| 4058 | +\indexlibrarymember{end}{optional}% |
| 4059 | +\begin{itemdecl} |
| 4060 | +constexpr iterator end() noexcept; |
| 4061 | +constexpr const_iterator end() const noexcept; |
| 4062 | +\end{itemdecl} |
| 4063 | + |
| 4064 | +\begin{itemdescr} |
| 4065 | +\pnum |
| 4066 | +\returns |
| 4067 | +\tcode{begin() + has_value()}. |
| 4068 | +\end{itemdescr} |
| 4069 | + |
4004 | 4070 | \rSec3[optional.observe]{Observers}
|
4005 | 4071 |
|
4006 | 4072 | \indexlibrarymember{operator->}{optional}%
|
|
0 commit comments