[optional.ref.observe]

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

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

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

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

[ð](#itemdecl:1)

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

[1](#1)

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

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

[2](#2)

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

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

[ð](#itemdecl:2)

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

[3](#3)

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

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

[4](#4)

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

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

[ð](#itemdecl:3)

`constexpr explicit operator bool() const noexcept;
`

[5](#5)

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

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

[ð](#itemdecl:4)

`constexpr bool has_value() const noexcept;
`

[6](#6)

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

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

[ð](#itemdecl:5)

`constexpr T& value() const;
`

[7](#7)

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

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

[ð](#itemdecl:6)

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

[8](#8)

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

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

[9](#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[.](#9.sentence-1)

[10](#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));
