[#absl-optional_ref-0c]
= xref:absl.adoc[absl]::optional&lowbar;ref
:relfileprefix: ../
:mrdocs:

A `std&colon;&colon;optional`&hyphen;like interface around a `T&ast;`&period;

== Synopsis

Declared in `&lt;absl&sol;types&sol;optional&lowbar;ref&period;h&gt;`

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;typename T&gt;
class optional&lowbar;ref;
----

== Description

Similar to C&plus;&plus;26&apos;s `std&colon;&colon;optional&lt;T&amp;&gt;`, but it also permits construction from rvalues&period; It makes it easier for functions to accept nullable object addresses, regardless of whether they point to temporaries&period; It is trivially copyable and destructible, so it should be passed by value&period;

== Type Aliases

[cols="1,4"]
|===
| Name| Description
| xref:absl/optional_ref-0c/value_type.adoc[`value&lowbar;type`] 
| The referenced value type&period;
|===


== Member Functions

[cols="1,4"]
|===
| Name| Description
| xref:absl/optional_ref-0c/2constructor-093.adoc[`optional&lowbar;ref`]         [.small]#[constructor]#
| Constructors
| xref:absl/optional_ref-0c/operator_assign.adoc[`operator&equals;`]  [.small]#[deleted]#
| Assignment is deleted&semi; `optional&lowbar;ref` is not assignable&period;
| xref:absl/optional_ref-0c/as_optional.adoc[`as&lowbar;optional`] 
| Represents the `optional&lowbar;ref` as a `std&colon;&colon;optional`&period;
| xref:absl/optional_ref-0c/as_pointer.adoc[`as&lowbar;pointer`] 
| Represents the `optional&lowbar;ref` as a `T&ast;` pointer&period;
| xref:absl/optional_ref-0c/has_value.adoc[`has&lowbar;value`] 
| Determines whether the `optional&lowbar;ref` contains a value&period;
| xref:absl/optional_ref-0c/operator_star.adoc[`operator&ast;`] 
| Accesses the underlying value&semi; undefined behavior if empty&period;
| xref:absl/optional_ref-0c/operator_ptr.adoc[`operator&hyphen;&gt;`] 
| Accesses members of the underlying value&semi; undefined behavior if empty&period;
| xref:absl/optional_ref-0c/value.adoc[`value`] 
| Returns a reference to the underlying value&period;
| xref:absl/optional_ref-0c/value_or.adoc[`value&lowbar;or`] 
| Returns the value if present, otherwise `default&lowbar;value`&period;
|===


== Deduction Guides

[cols="1,4"]
|===
| Name| Description
| xref:absl/optional_ref-02.adoc[`optional&lowbar;ref&lt;T&gt;`] 
| Deduces `optional&lowbar;ref&lt;T&gt;` from a mutable lvalue&period;
| xref:absl/optional_ref-0b.adoc[`optional&lowbar;ref&lt;T&gt;`] 
| Deduces `optional&lowbar;ref&lt;T&gt;` from a mutable `std&colon;&colon;optional`&period;
| xref:absl/optional_ref-01.adoc[`optional&lowbar;ref&lt;T&gt;`] 
| Deduces `optional&lowbar;ref&lt;T&gt;` from a pointer&period;
| xref:absl/optional_ref-00.adoc[`optional&lowbar;ref&lt;T const&gt;`] 
| Deduces `optional&lowbar;ref&lt;const T&gt;` from a const lvalue&period;
| xref:absl/optional_ref-05.adoc[`optional&lowbar;ref&lt;T const&gt;`] 
| Deduces `optional&lowbar;ref&lt;const T&gt;` from a const `std&colon;&colon;optional`&period;
|===


== Non-Member Functions

[cols="1,4"]
|===
| Name| Description
| xref:absl/operator_not_eq-018.adoc[`operator!&equals;`]
| Tests whether two `optional&lowbar;ref`s differ&period;
| xref:absl/operator_not_eq-065.adoc[`operator!&equals;`]
| Tests whether an `optional&lowbar;ref` differs from a value&period;
| xref:absl/operator_not_eq-0cb.adoc[`operator!&equals;`]
| Tests whether an `optional&lowbar;ref` holds a value&period;
| xref:absl/operator_eq-009.adoc[`operator&equals;&equals;`]
| Compares the referenced value of an `optional&lowbar;ref` to a value&period;
| xref:absl/operator_eq-06f.adoc[`operator&equals;&equals;`]
| Tests whether an `optional&lowbar;ref` is empty&period;
| xref:absl/operator_eq-0fb.adoc[`operator&equals;&equals;`]
| Compares the referenced values of two `optional&lowbar;ref`s&period;
|===


[.small]#Created with https://www.mrdocs.com[MrDocs]#
