|
|
constexpr | optional_ptr () noexcept |
| | Default constructor creates a disengaged optional.
|
| |
|
constexpr | optional_ptr (std::nullptr_t) noexcept |
| | Constructor for nullptr (creates a disengaged optional)
|
| |
|
constexpr | optional_ptr (optional_ptr &&p_other) noexcept=delete |
| | Move constructor is deleted.
|
| |
| constexpr | optional_ptr (strong_ptr< T > const &value) noexcept |
| | Construct from a strong_ptr lvalue.
|
| |
| constexpr | optional_ptr (optional_ptr const &p_other) |
| | Copy constructor.
|
| |
template<typename U >
requires (std::is_convertible_v<U*, T*>) |
| constexpr | optional_ptr (strong_ptr< U > const &p_value) |
| | Converting constructor from a strong_ptr.
|
| |
|
constexpr optional_ptr & | operator= (optional_ptr &&other) noexcept=delete |
| | Move assignment operator is deleted.
|
| |
| constexpr optional_ptr & | operator= (optional_ptr const &other) |
| | Copy assignment operator.
|
| |
| constexpr optional_ptr & | operator= (strong_ptr< T > const &value) noexcept |
| | Assignment from a strong_ptr.
|
| |
template<typename U >
requires (std::is_convertible_v<U*, T*>) |
| constexpr optional_ptr & | operator= (strong_ptr< U > const &p_value) noexcept |
| | Converting assignment from a strong_ptr.
|
| |
| constexpr optional_ptr & | operator= (std::nullptr_t) noexcept |
| | Assignment from nullptr (resets to disengaged state)
|
| |
| | ~optional_ptr () |
| | Destructor.
|
| |
| constexpr bool | has_value () const noexcept |
| | Check if the optional_ptr is engaged.
|
| |
| constexpr | operator bool () const noexcept |
| | Check if the optional_ptr is engaged.
|
| |
| constexpr strong_ptr< T > & | value () |
| | Access the contained value, throw if not engaged.
|
| |
| constexpr strong_ptr< T > const & | value () const |
| | Access the contained value, throw if not engaged (const version)
|
| |
| constexpr | operator strong_ptr< T > () |
| | Implicitly convert to a strong_ptr<T>
|
| |
| constexpr | operator strong_ptr< T > () const |
| | Implicitly convert to a strong_ptr<T> (const version)
|
| |
template<typename U >
requires (std::is_convertible_v<T*, U*> && !std::is_same_v<T, U>) |
| constexpr | operator strong_ptr< U > () |
| | Implicitly convert to a strong_ptr for polymorphic types.
|
| |
template<typename U >
requires (std::is_convertible_v<T*, U*> && !std::is_same_v<T, U>) |
| constexpr | operator strong_ptr< U > () const |
| | Implicitly convert to a strong_ptr for polymorphic types (const version)
|
| |
| constexpr auto * | operator-> () |
| | Arrow operator for accessing members of the contained object.
|
| |
| constexpr auto * | operator-> () const |
| | Arrow operator for accessing members of the contained object (const version)
|
| |
| constexpr auto & | operator* () |
| | Dereference operator for accessing the contained object.
|
| |
| constexpr auto & | operator* () const |
| | Dereference operator for accessing the contained object (const version)
|
| |
|
constexpr void | reset () noexcept |
| | Reset the optional to a disengaged state.
|
| |
| template<typename... Args> |
| constexpr strong_ptr< T > & | emplace (Args &&... args) |
| | Emplace a new value.
|
| |
| constexpr void | swap (optional_ptr &other) noexcept |
| | Swap the contents of this optional_ptr with another.
|
| |
template<typename T>
class atlas::memory::optional_ptr< T >
Optional, nullable, smart pointer that works with hal::strong_ptr.
optional_ptr provides a way to represent a strong_ptr that may or may not be present. Unlike strong_ptr, which is always valid, optional_ptr can be in a "disengaged" state where it doesn't reference any object.
Use optional_ptr when you need a nullable reference to a reference-counted object, such as:
- Representing the absence of a value
- Return values from functions that may fail
- Results of locking a weak_ptr
Example usage:
optional_ptr<my_driver> opt1;
auto ptr = make_strong_ptr<my_driver>(allocator, args...);
optional_ptr<my_driver> opt2 = ptr;
if (opt2) {
opt2->doSomething();
}
opt2.reset();
- Template Parameters
-