[optional.optional.ref]

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

## 22.5 Optional objects [[optional]](optional#optional.ref)

### 22.5.4 Partial specialization of optional for reference types [optional.optional.ref]

#### [22.5.4.1](#general) General [[optional.optional.ref.general]](optional.optional.ref.general)

namespace std {template<class T>class optional<T&> {public:using value_type = T; using iterator = *implementation-defined*; // see [[optional.ref.iterators]](#optional.ref.iterators "22.5.4.5 Iterator support")public:// [[optional.ref.ctor]](#optional.ref.ctor "22.5.4.2 Constructors"), constructorsconstexpr optional() noexcept = default; constexpr optional(nullopt_t) noexcept : optional() {}constexpr optional(const optional& rhs) noexcept = default; template<class Arg>constexpr explicit optional(in_place_t, Arg&& arg); template<class U>constexpr explicit(*see below*) optional(U&& u) noexcept(*see below*); template<class U>constexpr explicit(*see below*) optional(optional<U>& rhs) noexcept(*see below*); template<class U>constexpr explicit(*see below*) optional(const optional<U>& rhs) noexcept(*see below*); template<class U>constexpr explicit(*see below*) optional(optional<U>&& rhs) noexcept(*see below*); template<class U>constexpr explicit(*see below*) optional(const optional<U>&& rhs) noexcept(*see below*); constexpr ~optional() = default; // [[optional.ref.assign]](#optional.ref.assign "22.5.4.3 Assignment"), assignmentconstexpr optional& operator=(nullopt_t) noexcept; constexpr optional& operator=(const optional& rhs) noexcept = default; template<class U> constexpr T& emplace(U&& u) noexcept(*see below*); // [[optional.ref.swap]](#optional.ref.swap "22.5.4.4 Swap"), swapconstexpr void swap(optional& rhs) noexcept; // [[optional.ref.iterators]](#optional.ref.iterators "22.5.4.5 Iterator support"), iterator supportconstexpr iterator begin() const noexcept; constexpr iterator end() const noexcept; // [[optional.ref.observe]](#optional.ref.observe "22.5.4.6 Observers"), observersconstexpr T* operator->() const noexcept; constexpr T& operator*() const noexcept; constexpr explicit operator bool() const noexcept; constexpr bool has_value() const noexcept; constexpr T& value() const; // freestanding-deletedtemplate<class U = remove_cv_t<T>>constexpr remove_cv_t<T> value_or(U&& u) const; // [[optional.ref.monadic]](#optional.ref.monadic "22.5.4.7 Monadic operations"), monadic operationstemplate<class F> constexpr auto and_then(F&& f) const; template<class F> constexpr optional<invoke_result_t<F, T&>> transform(F&& f) const; template<class F> constexpr optional or_else(F&& f) const; // [[optional.ref.mod]](#optional.ref.mod "22.5.4.8 Modifiers"), modifiersconstexpr void reset() noexcept; private: T* *val* = nullptr; // *exposition only*// [[optional.ref.expos]](#optional.ref.expos "22.5.4.9 Exposition only helper functions"), exposition only helper functionstemplate<class U>constexpr void *convert-ref-init-val*(U&& u); // *exposition only*};}

[1](#general-1)

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

An object of optional<T&>[*contains a value*](#def:contains_a_value,optional.ref "22.5.4.1 General [optional.optional.ref.general]") if and only if *val* != nullptr is true[.](#general-1.sentence-1)

When an optional<T&> contains a value,
the [*contained value*](#def:contained_value,optional.ref "22.5.4.1 General [optional.optional.ref.general]") is a reference to **val*[.](#general-1.sentence-2)

#### [22.5.4.2](#optional.ref.ctor) Constructors [[optional.ref.ctor]](optional.ref.ctor)

[ð](#optional.ref.ctor-itemdecl:1)

`template<class Arg>
  constexpr explicit optional(in_place_t, Arg&& arg);
`

[1](#optional.ref.ctor-1)

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

*Constraints*: 

- [(1.1)](#optional.ref.ctor-1.1)

is_constructible_v<T&, Arg> is true, and

- [(1.2)](#optional.ref.ctor-1.2)

reference_constructs_from_temporary_v<T&, Arg> is false[.](#optional.ref.ctor-1.sentence-1)

[2](#optional.ref.ctor-2)

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

*Effects*: Equivalent to: *convert-ref-init-val*(std​::​forward<Arg>(arg))[.](#optional.ref.ctor-2.sentence-1)

[3](#optional.ref.ctor-3)

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

*Postconditions*: *this contains a value[.](#optional.ref.ctor-3.sentence-1)

[ð](#optional.ref.ctor-itemdecl:2)

`template<class U>
  constexpr explicit(!is_convertible_v<U, T&>)
  optional(U&& u) noexcept(is_nothrow_constructible_v<T&, U>);
`

[4](#optional.ref.ctor-4)

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

*Constraints*: 

- [(4.1)](#optional.ref.ctor-4.1)

is_same_v<remove_cvref_t<U>, optional> is false,

- [(4.2)](#optional.ref.ctor-4.2)

is_same_v<remove_cvref_t<U>, in_place_t> is false, and

- [(4.3)](#optional.ref.ctor-4.3)

is_constructible_v<T&, U> is true[.](#optional.ref.ctor-4.sentence-1)

[5](#optional.ref.ctor-5)

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

*Effects*: Equivalent to: *convert-ref-init-val*(std​::​forward<U>(u))[.](#optional.ref.ctor-5.sentence-1)

[6](#optional.ref.ctor-6)

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

*Postconditions*: *this contains a value[.](#optional.ref.ctor-6.sentence-1)

[7](#optional.ref.ctor-7)

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

*Remarks*: This constructor is defined as deleted ifreference_constructs_from_temporary_v<T&, U> is true[.](#optional.ref.ctor-7.sentence-1)

[ð](#optional.ref.ctor-itemdecl:3)

`template<class U>
  constexpr explicit(!is_convertible_v<U&, T&>)
  optional(optional<U>& rhs) noexcept(is_nothrow_constructible_v<T&, U&>);
`

[8](#optional.ref.ctor-8)

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

*Constraints*: 

- [(8.1)](#optional.ref.ctor-8.1)

is_same_v<remove_cv_t<T>, optional<U>> is false,

- [(8.2)](#optional.ref.ctor-8.2)

is_same_v<T&, U> is false, and

- [(8.3)](#optional.ref.ctor-8.3)

is_constructible_v<T&, U&> is true[.](#optional.ref.ctor-8.sentence-1)

[9](#optional.ref.ctor-9)

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

*Effects*: Equivalent to:if (rhs.has_value()) *convert-ref-init-val*(*rhs);

[10](#optional.ref.ctor-10)

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

*Remarks*: This constructor is defined as deleted ifreference_constructs_from_temporary_v<T&, U&> is true[.](#optional.ref.ctor-10.sentence-1)

[ð](#optional.ref.ctor-itemdecl:4)

`template<class U>
  constexpr explicit(!is_convertible_v<const U&, T&>)
  optional(const optional<U>& rhs) noexcept(is_nothrow_constructible_v<T&, const U&>);
`

[11](#optional.ref.ctor-11)

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

*Constraints*: 

- [(11.1)](#optional.ref.ctor-11.1)

is_same_v<remove_cv_t<T>, optional<U>> is false,

- [(11.2)](#optional.ref.ctor-11.2)

is_same_v<T&, U> is false, and

- [(11.3)](#optional.ref.ctor-11.3)

is_constructible_v<T&, const U&> is true[.](#optional.ref.ctor-11.sentence-1)

[12](#optional.ref.ctor-12)

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

*Effects*: Equivalent to:if (rhs.has_value()) *convert-ref-init-val*(*rhs);

[13](#optional.ref.ctor-13)

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

*Remarks*: This constructor is defined as deleted ifreference_constructs_from_temporary_v<T&, const U&> is true[.](#optional.ref.ctor-13.sentence-1)

[ð](#optional.ref.ctor-itemdecl:5)

`template<class U>
  constexpr explicit(!is_convertible_v<U, T&>)
  optional(optional<U>&& rhs) noexcept(is_nothrow_constructible_v<T&, U>);
`

[14](#optional.ref.ctor-14)

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

*Constraints*: 

- [(14.1)](#optional.ref.ctor-14.1)

is_same_v<remove_cv_t<T>, optional<U>> is false,

- [(14.2)](#optional.ref.ctor-14.2)

is_same_v<T&, U> is false, and

- [(14.3)](#optional.ref.ctor-14.3)

is_constructible_v<T&, U> is true[.](#optional.ref.ctor-14.sentence-1)

[15](#optional.ref.ctor-15)

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

*Effects*: Equivalent to:if (rhs.has_value()) *convert-ref-init-val*(*std::move(rhs));

[16](#optional.ref.ctor-16)

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

*Remarks*: This constructor is defined as deleted ifreference_constructs_from_temporary_v<T&, U> is true[.](#optional.ref.ctor-16.sentence-1)

[ð](#optional.ref.ctor-itemdecl:6)

`template<class U>
  constexpr explicit(!is_convertible_v<const U, T&>)
  optional(const optional<U>&& rhs) noexcept(is_nothrow_constructible_v<T&, const U>);
`

[17](#optional.ref.ctor-17)

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

*Constraints*: 

- [(17.1)](#optional.ref.ctor-17.1)

is_same_v<remove_cv_t<T>, optional<U>> is false,

- [(17.2)](#optional.ref.ctor-17.2)

is_same_v<T&, U> is false, and

- [(17.3)](#optional.ref.ctor-17.3)

is_constructible_v<T&, const U> is true[.](#optional.ref.ctor-17.sentence-1)

[18](#optional.ref.ctor-18)

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

*Effects*: Equivalent to:if (rhs.has_value()) *convert-ref-init-val*(*std::move(rhs));

[19](#optional.ref.ctor-19)

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

*Remarks*: This constructor is defined as deleted ifreference_constructs_from_temporary_v<T&, const U> is true[.](#optional.ref.ctor-19.sentence-1)

#### [22.5.4.3](#optional.ref.assign) Assignment [[optional.ref.assign]](optional.ref.assign)

[ð](#optional.ref.assign-itemdecl:1)

`constexpr optional& operator=(nullopt_t) noexcept;
`

[1](#optional.ref.assign-1)

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

*Effects*: Assigns nullptr to *val*[.](#optional.ref.assign-1.sentence-1)

[2](#optional.ref.assign-2)

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

*Postconditions*: *this does not contain a value[.](#optional.ref.assign-2.sentence-1)

[3](#optional.ref.assign-3)

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

*Returns*: *this[.](#optional.ref.assign-3.sentence-1)

[ð](#optional.ref.assign-itemdecl:2)

`template<class U>
  constexpr T& emplace(U&& u) noexcept(is_nothrow_constructible_v<T&, U>);
`

[4](#optional.ref.assign-4)

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

*Constraints*: 

- [(4.1)](#optional.ref.assign-4.1)

is_constructible_v<T&, U> is true, and

- [(4.2)](#optional.ref.assign-4.2)

reference_constructs_from_temporary_v<T&, U> is false[.](#optional.ref.assign-4.sentence-1)

[5](#optional.ref.assign-5)

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

*Effects*: Equivalent to: *convert-ref-init-val*(std​::​forward<U>(u))[.](#optional.ref.assign-5.sentence-1)

#### [22.5.4.4](#optional.ref.swap) Swap [[optional.ref.swap]](optional.ref.swap)

[ð](#optional.ref.swap-itemdecl:1)

`constexpr void swap(optional& rhs) noexcept;
`

[1](#optional.ref.swap-1)

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

*Effects*: Equivalent to: swap(*val*, rhs.*val*)[.](#optional.ref.swap-1.sentence-1)

#### [22.5.4.5](#optional.ref.iterators) Iterator support [[optional.ref.iterators]](optional.ref.iterators)

[ð](#optional.ref.iterators-itemdecl:1)

`using iterator = implementation-defined;
`

[1](#optional.ref.iterators-1)

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

This type
models [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")),
meets the *Cpp17RandomAccessIterator* requirements ([[random.access.iterators]](random.access.iterators "24.3.5.7 Random access iterators")),
and meets the requirements for constexpr iterators ([[iterator.requirements.general]](iterator.requirements.general "24.3.1 General")),
with value type remove_cv_t<T>[.](#optional.ref.iterators-1.sentence-1)

The reference type is T& for iterator[.](#optional.ref.iterators-1.sentence-2)

[2](#optional.ref.iterators-2)

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

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

[ð](#optional.ref.iterators-itemdecl:2)

`constexpr iterator begin() const noexcept;
`

[3](#optional.ref.iterators-3)

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

*Returns*: If has_value() is true,
 an iterator referring to **val*[.](#optional.ref.iterators-3.sentence-1)

Otherwise, a past-the-end iterator value[.](#optional.ref.iterators-3.sentence-2)

[ð](#optional.ref.iterators-itemdecl:3)

`constexpr iterator end() const noexcept;
`

[4](#optional.ref.iterators-4)

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

*Returns*: begin() + has_value()[.](#optional.ref.iterators-4.sentence-1)

#### [22.5.4.6](#optional.ref.observe) Observers [[optional.ref.observe]](optional.ref.observe)

[ð](#optional.ref.observe-itemdecl:1)

`constexpr T* operator->() const noexcept;
`

[1](#optional.ref.observe-1)

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

*Hardened preconditions*: has_value() is true[.](#optional.ref.observe-1.sentence-1)

[2](#optional.ref.observe-2)

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

*Returns*: *val*[.](#optional.ref.observe-2.sentence-1)

[ð](#optional.ref.observe-itemdecl:2)

`constexpr T& operator*() const noexcept;
`

[3](#optional.ref.observe-3)

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

*Hardened preconditions*: has_value() is true[.](#optional.ref.observe-3.sentence-1)

[4](#optional.ref.observe-4)

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

*Returns*: **val*[.](#optional.ref.observe-4.sentence-1)

[ð](#optional.ref.observe-itemdecl:3)

`constexpr explicit operator bool() const noexcept;
`

[5](#optional.ref.observe-5)

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

*Returns*: *val* != nullptr[.](#optional.ref.observe-5.sentence-1)

[ð](#optional.ref.observe-itemdecl:4)

`constexpr bool has_value() const noexcept;
`

[6](#optional.ref.observe-6)

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

*Returns*: *val* != nullptr[.](#optional.ref.observe-6.sentence-1)

[ð](#optional.ref.observe-itemdecl:5)

`constexpr T& value() const;
`

[7](#optional.ref.observe-7)

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

*Effects*: Equivalent to:return has_value() ? **val* : throw bad_optional_access();

[ð](#optional.ref.observe-itemdecl:6)

`template<class U = remove_cv_t<T>> constexpr remove_cv_t<T> value_or(U&& u) const;
`

[8](#optional.ref.observe-8)

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

Let X be remove_cv_t<T>[.](#optional.ref.observe-8.sentence-1)

[9](#optional.ref.observe-9)

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

*Mandates*: is_constructible_v<X, T&> && is_convertible_v<U, X> is true[.](#optional.ref.observe-9.sentence-1)

[10](#optional.ref.observe-10)

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

*Effects*: Equivalent to:return has_value() ? **val* : static_cast<X>(std::forward<U>(u));

#### [22.5.4.7](#optional.ref.monadic) Monadic operations [[optional.ref.monadic]](optional.ref.monadic)

[ð](#optional.ref.monadic-itemdecl:1)

`template<class F> constexpr auto and_then(F&& f) const;
`

[1](#optional.ref.monadic-1)

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

Let U be invoke_result_t<F, T&>[.](#optional.ref.monadic-1.sentence-1)

[2](#optional.ref.monadic-2)

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

*Mandates*: remove_cvref_t<U> is a specialization of optional[.](#optional.ref.monadic-2.sentence-1)

[3](#optional.ref.monadic-3)

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

*Effects*: Equivalent to:if (has_value()) {return invoke(std::forward<F>(f), **val*);} else {return remove_cvref_t<U>();}

[ð](#optional.ref.monadic-itemdecl:2)

`template<class F>
  constexpr optional<remove_cv_t<invoke_result_t<F, T&>>> transform(F&& f) const;
`

[4](#optional.ref.monadic-4)

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

Let U be remove_cv_t<invoke_result_t<F, T&>>[.](#optional.ref.monadic-4.sentence-1)

[5](#optional.ref.monadic-5)

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

*Mandates*: The declarationU u(invoke(std::forward<F>(f), **val*)); is well-formed for some invented variable u[.](#optional.ref.monadic-5.sentence-1)

[*Note [1](#optional.ref.monadic-note-1)*:

There is no requirement that U is movable ([[dcl.init.general]](dcl.init.general "9.5.1 General"))[.](#optional.ref.monadic-5.sentence-2)

â *end note*]

[6](#optional.ref.monadic-6)

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

*Returns*: If *this contains a value, an optional<U> object
whose contained value is direct-non-list-initialized withinvoke(std​::​forward<F>(f), **val*);
otherwise, optional<U>()[.](#optional.ref.monadic-6.sentence-1)

[ð](#optional.ref.monadic-itemdecl:3)

`template<class F> constexpr optional or_else(F&& f) const;
`

[7](#optional.ref.monadic-7)

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

*Constraints*: F models [invocable](concept.invocable#concept:invocable "18.7.2 Concept invocable [concept.invocable]")[.](#optional.ref.monadic-7.sentence-1)

[8](#optional.ref.monadic-8)

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

*Mandates*: is_same_v<remove_cvref_t<invoke_result_t<F>>, optional> is true[.](#optional.ref.monadic-8.sentence-1)

[9](#optional.ref.monadic-9)

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

*Effects*: Equivalent to:if (has_value()) {return **val*;} else {return std::forward<F>(f)();}

#### [22.5.4.8](#optional.ref.mod) Modifiers [[optional.ref.mod]](optional.ref.mod)

[ð](#optional.ref.mod-itemdecl:1)

`constexpr void reset() noexcept;
`

[1](#optional.ref.mod-1)

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

*Effects*: Assigns nullptr to *val*[.](#optional.ref.mod-1.sentence-1)

[2](#optional.ref.mod-2)

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

*Postconditions*: *this does not contain a value[.](#optional.ref.mod-2.sentence-1)

#### [22.5.4.9](#optional.ref.expos) Exposition only helper functions [[optional.ref.expos]](optional.ref.expos)

[ð](#optional.ref.expos-itemdecl:1)

`template<class U>
  constexpr void convert-ref-init-val(U&& u);  // exposition only
`

[1](#optional.ref.expos-1)

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

*Effects*: Creates a variable r as if by T& r(std​::​forward<U>(u)); and then initializes *val* with addressof(r)[.](#optional.ref.expos-1.sentence-1)
