|
|
Donner SVG Editor & Engine
SVG-native editor and embeddable SVG2 + CSS3 engine in C++20, with GPU (WebGPU) and compact CPU renderers, built for correctness, security, and performance.
|
A class that simulates an optional reference to a constant object of type T. More...
#include "donner/base/OptionalRef.h"
Public Types | |
| using | Type = const std::remove_cvref_t<T> |
| Type of the referenced object. | |
Public Member Functions | |
| constexpr | OptionalRef () noexcept=default |
| Constructs an empty OptionalRef. | |
| OptionalRef (std::nullopt_t nullopt) noexcept | |
| Constructs an empty OptionalRef from a std::nullopt. | |
| constexpr | OptionalRef (const T &ref) noexcept |
| Constructs an OptionalRef that contains a reference to the given object. | |
| ~OptionalRef () noexcept=default | |
| Destructor. | |
| constexpr | OptionalRef (const OptionalRef &other) noexcept=default |
| Copy constructor. | |
| constexpr | OptionalRef (OptionalRef &&other) noexcept=default |
| Move constructor. | |
| OptionalRef & | operator= (const OptionalRef &other) noexcept=default |
| Copy assignment operator. | |
| OptionalRef & | operator= (OptionalRef &&other) noexcept=default |
| Move assignment operator. | |
| OptionalRef & | operator= (const T &ref) noexcept |
| Assigns a reference to the given object. | |
| void | reset () noexcept |
| Resets the OptionalRef to be empty. | |
| constexpr | operator bool () const noexcept |
| Returns true if the OptionalRef contains a reference. | |
| constexpr bool | hasValue () const noexcept |
| Returns true if the OptionalRef contains a reference. | |
| constexpr const T & | value () const |
| Returns a const reference to the referenced object. | |
| constexpr const T & | operator* () const |
| Returns a const reference to the referenced object. | |
| constexpr const Type * | operator-> () const noexcept |
| Returns a pointer to the referenced object. | |
| constexpr | operator std::optional< T > () const |
| Implicit conversion to a std::optional<T>. | |
Friends | |
| constexpr friend bool | operator== (const OptionalRef &lhs, const OptionalRef &rhs) |
| Equality operator to another OptionalRef. | |
| constexpr friend bool | operator== (const OptionalRef &lhs, std::nullopt_t) |
| Equality operator to a std::nullopt. | |
| constexpr friend bool | operator== (const OptionalRef &lhs, const T &rhs) |
| Equality operator for a set value. | |
| std::ostream & | operator<< (std::ostream &os, const OptionalRef &opt) |
| Stream output operator. | |
A class that simulates an optional reference to a constant object of type T.
This class behaves similarly to std::optional<const T&>, which is proposed by the upcoming P2988 std::optional<T&> proposal, providing a way to store an optional reference to a constant object. Since std::optional cannot be used with reference types, OptionalRef provides a workaround.
| T | The type of the object to reference. |
|
inlinenoexcept |
Constructs an empty OptionalRef from a std::nullopt.
| nullopt | Accepts std::nullopt to construct an empty OptionalRef. |
|
inlineconstexprnoexcept |
Constructs an OptionalRef that contains a reference to the given object.
| ref | The object to reference. |
|
constexprdefaultnoexcept |
Copy constructor.
| other | The other OptionalRef to copy from. |
|
constexprdefaultnoexcept |
Move constructor.
| other | The other OptionalRef to move from. |
|
inlineconstexprnoexcept |
Returns true if the OptionalRef contains a reference.
|
inlineexplicitconstexprnoexcept |
Returns true if the OptionalRef contains a reference.
|
inlineconstexpr |
Returns a const reference to the referenced object.
|
inlineconstexprnoexcept |
Returns a pointer to the referenced object.
|
defaultnoexcept |
Copy assignment operator.
| other | The other OptionalRef to copy from. |
|
inlinenoexcept |
Assigns a reference to the given object.
| ref | The object to reference. |
|
defaultnoexcept |
Move assignment operator.
| other | The other OptionalRef to move from. |
|
inlineconstexpr |
Returns a const reference to the referenced object.
|
friend |
Stream output operator.
| os | Output stream. |
| opt | The OptionalRef to output. |