[optional.iterators]

# 22 General utilities library [[utilities]](./#utilities)

## 22.5 Optional objects [[optional]](optional#iterators)

### 22.5.3 Class template optional [[optional.optional]](optional.optional#optional.iterators)

#### 22.5.3.6 Iterator support [optional.iterators]

[ð](#lib:iterator,optional)

`using iterator       = implementation-defined;
using const_iterator = implementation-defined;
`

[1](#1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4059)

These types
model [contiguous_iterator](iterator.concept.contiguous#concept:contiguous_iterator "24.3.4.14 Concept contiguous_­iterator [iterator.concept.contiguous]") ([[iterator.concept.contiguous]](iterator.concept.contiguous "24.3.4.14 Concept contiguous_­iterator")),
meet the [*Cpp17RandomAccessIterator*](random.access.iterators#:Cpp17RandomAccessIterator "24.3.5.7 Random access iterators [random.access.iterators]") requirements ([[random.access.iterators]](random.access.iterators "24.3.5.7 Random access iterators")), and
meet the requirements for constexpr iterators ([[iterator.requirements.general]](iterator.requirements.general "24.3.1 General")),
with value type remove_cv_t<T>[.](#1.sentence-1)

The reference type is T& for iterator andconst T& for const_iterator[.](#1.sentence-2)

[2](#2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4068)

All requirements on container iterators ([[container.reqmts]](container.reqmts "23.2.2.2 Container requirements")) apply tooptional​::​iterator and optional​::​const_iterator as well[.](#2.sentence-1)

[3](#3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4072)

Any operation that initializes or destroys the contained value of an optional object invalidates all iterators into that object[.](#3.sentence-1)

[ð](#lib:begin,optional)

`constexpr iterator begin() noexcept;
constexpr const_iterator begin() const noexcept;
`

[4](#4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4083)

*Returns*: If has_value() is true,
an iterator referring to the contained value[.](#4.sentence-1)

Otherwise, a past-the-end iterator value[.](#4.sentence-2)

[ð](#lib:end,optional)

`constexpr iterator end() noexcept;
constexpr const_iterator end() const noexcept;
`

[5](#5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4097)

*Returns*: begin() + has_value()[.](#5.sentence-1)
