[optional.optional.ref.general] (original) (raw)
22 General utilities library [utilities]
22.5 Optional objects [optional]
22.5.4 Partial specialization of optional for reference types [optional.optional.ref]
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; public: constexpr 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;constexpr optional& operator=(nullopt_t) noexcept;constexpr optional& operator=(const optional& rhs) noexcept = default;template<class U> constexpr T& emplace(U&& u) noexcept(see below);constexpr void swap(optional& rhs) noexcept;constexpr iterator begin() const noexcept;constexpr iterator end() const noexcept;constexpr 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; template<class U = remove_cv_t<T>> constexpr remove_cv_t<T> value_or(U&& u) const;template<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;constexpr void reset() noexcept;private: T* val = nullptr; template<class U> constexpr void convert-ref-init-val(U&& u); };}
An object of type optional<T&> contains a valueif and only if val != nullptr is true.
When an optional<T&> contains a value, the contained valueis a reference to *val.