[expected.object.obs]

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

## 22.8 Expected objects [[expected]](expected#object.obs)

### 22.8.6 Class template expected [[expected.expected]](expected.expected#expected.object.obs)

#### 22.8.6.6 Observers [expected.object.obs]

[ð](#lib:operator-%3e,expected)

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

[1](#1)

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

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

[2](#2)

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

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

[ð](#lib:operator*,expected)

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

[3](#3)

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

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

[4](#4)

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

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

[ð](#lib:operator*,expected_)

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

[5](#5)

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

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

[6](#6)

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

*Returns*: std​::​move(*val*)[.](#6.sentence-1)

[ð](#lib:operator_bool,expected)

`constexpr explicit operator bool() const noexcept;
constexpr bool has_value() const noexcept;
`

[7](#7)

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

*Returns*: *has_val*[.](#7.sentence-1)

[ð](#lib:value,expected)

`constexpr const T& value() const &;
constexpr T& value() &;
`

[8](#8)

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

*Mandates*: is_copy_constructible_v<E> is true[.](#8.sentence-1)

[9](#9)

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

*Returns*: *val*, if has_value() is true[.](#9.sentence-1)

[10](#10)

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

*Throws*: bad_expected_access(as_const(error())) if has_value() is false[.](#10.sentence-1)

[ð](#lib:value,expected_)

`constexpr T&& value() &&;
constexpr const T&& value() const &&;
`

[11](#11)

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

*Mandates*: is_copy_constructible_v<E> is true andis_constructible_v<E, decltype(std​::​move(error()))> is true[.](#11.sentence-1)

[12](#12)

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

*Returns*: std​::​move(*val*), if has_value() is true[.](#12.sentence-1)

[13](#13)

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

*Throws*: bad_expected_access(std​::​move(error())) if has_value() is false[.](#13.sentence-1)

[ð](#lib:error,expected)

`constexpr const E& error() const & noexcept;
constexpr E& error() & noexcept;
`

[14](#14)

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

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

[15](#15)

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

*Returns*: *unex*[.](#15.sentence-1)

[ð](#lib:error,expected_)

`constexpr E&& error() && noexcept;
constexpr const E&& error() const && noexcept;
`

[16](#16)

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

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

[17](#17)

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

*Returns*: std​::​move(*unex*)[.](#17.sentence-1)

[ð](#lib:value_or,expected)

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

[18](#18)

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

*Mandates*: is_copy_constructible_v<T> is true andis_convertible_v<U, T> is true[.](#18.sentence-1)

[19](#19)

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

*Returns*: has_value() ? **this : static_cast<T>(std​::​forward<U>(v))[.](#19.sentence-1)

[ð](#lib:value_or,expected_)

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

[20](#20)

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

*Mandates*: is_move_constructible_v<T> is true andis_convertible_v<U, T> is true[.](#20.sentence-1)

[21](#21)

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

*Returns*: has_value() ? std​::​move(**this) : static_cast<T>(std​::​forward<U>(v))[.](#21.sentence-1)

[ð](#lib:error_or,expected)

`template<class G = E> constexpr E error_or(G&& e) const &;
`

[22](#22)

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

*Mandates*: is_copy_constructible_v<E> is true andis_convertible_v<G, E> is true[.](#22.sentence-1)

[23](#23)

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

*Returns*: std​::​forward<G>(e) if has_value() is true,error() otherwise[.](#23.sentence-1)

[ð](#lib:error_or,expected_)

`template<class G = E> constexpr E error_or(G&& e) &&;
`

[24](#24)

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

*Mandates*: is_move_constructible_v<E> is true andis_convertible_v<G, E> is true[.](#24.sentence-1)

[25](#25)

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

*Returns*: std​::​forward<G>(e) if has_value() is true,std​::​move(error()) otherwise[.](#25.sentence-1)
