[optional.optional.ref.general]

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

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

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

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