[#absl-optional_ref-0c] = xref:absl.adoc[absl]::optional_ref :relfileprefix: ../ :mrdocs: A `std::optional`‐like interface around a `T*`. == Synopsis Declared in `<absl/types/optional_ref.h>` [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- template<typename T> class optional_ref; ---- == Description Similar to C++26's `std::optional<T&>`, but it also permits construction from rvalues. It makes it easier for functions to accept nullable object addresses, regardless of whether they point to temporaries. It is trivially copyable and destructible, so it should be passed by value. == Type Aliases [cols="1,4"] |=== | Name| Description | xref:absl/optional_ref-0c/value_type.adoc[`value_type`] | The referenced value type. |=== == Member Functions [cols="1,4"] |=== | Name| Description | xref:absl/optional_ref-0c/2constructor-093.adoc[`optional_ref`] [.small]#[constructor]# | Constructors | xref:absl/optional_ref-0c/operator_assign.adoc[`operator=`] [.small]#[deleted]# | Assignment is deleted; `optional_ref` is not assignable. | xref:absl/optional_ref-0c/as_optional.adoc[`as_optional`] | Represents the `optional_ref` as a `std::optional`. | xref:absl/optional_ref-0c/as_pointer.adoc[`as_pointer`] | Represents the `optional_ref` as a `T*` pointer. | xref:absl/optional_ref-0c/has_value.adoc[`has_value`] | Determines whether the `optional_ref` contains a value. | xref:absl/optional_ref-0c/operator_star.adoc[`operator*`] | Accesses the underlying value; undefined behavior if empty. | xref:absl/optional_ref-0c/operator_ptr.adoc[`operator‐>`] | Accesses members of the underlying value; undefined behavior if empty. | xref:absl/optional_ref-0c/value.adoc[`value`] | Returns a reference to the underlying value. | xref:absl/optional_ref-0c/value_or.adoc[`value_or`] | Returns the value if present, otherwise `default_value`. |=== == Deduction Guides [cols="1,4"] |=== | Name| Description | xref:absl/optional_ref-02.adoc[`optional_ref<T>`] | Deduces `optional_ref<T>` from a mutable lvalue. | xref:absl/optional_ref-0b.adoc[`optional_ref<T>`] | Deduces `optional_ref<T>` from a mutable `std::optional`. | xref:absl/optional_ref-01.adoc[`optional_ref<T>`] | Deduces `optional_ref<T>` from a pointer. | xref:absl/optional_ref-00.adoc[`optional_ref<T const>`] | Deduces `optional_ref<const T>` from a const lvalue. | xref:absl/optional_ref-05.adoc[`optional_ref<T const>`] | Deduces `optional_ref<const T>` from a const `std::optional`. |=== == Non-Member Functions [cols="1,4"] |=== | Name| Description | xref:absl/operator_not_eq-018.adoc[`operator!=`] | Tests whether two `optional_ref`s differ. | xref:absl/operator_not_eq-065.adoc[`operator!=`] | Tests whether an `optional_ref` differs from a value. | xref:absl/operator_not_eq-0cb.adoc[`operator!=`] | Tests whether an `optional_ref` holds a value. | xref:absl/operator_eq-009.adoc[`operator==`] | Compares the referenced value of an `optional_ref` to a value. | xref:absl/operator_eq-06f.adoc[`operator==`] | Tests whether an `optional_ref` is empty. | xref:absl/operator_eq-0fb.adoc[`operator==`] | Compares the referenced values of two `optional_ref`s. |=== [.small]#Created with https://www.mrdocs.com[MrDocs]#