|
|
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>.
|
template<typename T>
class donner::OptionalRef< T >
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.
- Note
- The referenced object must outlive the OptionalRef. It is the responsibility of the user to ensure that the reference remains valid.
- Template Parameters
-
| T | The type of the object to reference. |