A std::optional‐like interface around a T*.
Synopsis
Declared in <absl/types/optional_ref.h>
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
Name |
Description |
The referenced value type. |
Member Functions
Name |
Description |
|
Constructors |
|
Assignment is deleted; |
Represents the |
|
Represents the |
|
Determines whether the |
|
Accesses the underlying value; undefined behavior if empty. |
|
Accesses members of the underlying value; undefined behavior if empty. |
|
Returns a reference to the underlying value. |
|
Returns the value if present, otherwise |
Deduction Guides
Name |
Description |
Deduces |
|
Deduces |
|
Deduces |
|
Deduces |
|
Deduces |
Non-Member Functions
Name |
Description |
Tests whether two `optional_ref`s differ. |
|
Tests whether an |
|
Tests whether an |
|
Compares the referenced value of an |
|
Tests whether an |
|
Compares the referenced values of two `optional_ref`s. |
Created with MrDocs