|
|
| strong_ptr ()=delete |
| | Delete default constructor - strong_ptr must always be valid.
|
| |
|
| strong_ptr (std::nullptr_t)=delete |
| | Delete nullptr constructor - strong_ptr must always be valid.
|
| |
| | strong_ptr (strong_ptr const &p_other) noexcept |
| | Copy constructor.
|
| |
template<typename U >
requires (std::is_convertible_v<U*, T*>) |
| | strong_ptr (strong_ptr< U > const &p_other) noexcept |
| | Converting copy constructor.
|
| |
| | strong_ptr (strong_ptr &&p_other) noexcept |
| | Move constructor that intentionally behaves like a copy constructor for safety.
|
| |
| strong_ptr & | operator= (strong_ptr &&p_other) noexcept |
| | Move assignment operator that behaves like a copy assignment for safety.
|
| |
| template<typename U > |
| | strong_ptr (strong_ptr< U > const &, void const *) noexcept |
| | Compile time error message for bad alias value.
|
| |
| template<typename U , detail::non_array_like M> |
| | strong_ptr (strong_ptr< U > const &p_other, M U::*p_member_ptr) noexcept |
| | Safe aliasing constructor for object members.
|
| |
| template<typename U , typename E , std::size_t N> |
| | strong_ptr (strong_ptr< U > const &p_other, std::array< E, N > U::*p_array_ptr, std::size_t p_index) |
| | Safe aliasing constructor for std::array members.
|
| |
| template<typename U , typename E , std::size_t N> |
| | strong_ptr (strong_ptr< U > const &p_other, E(U::*p_array_ptr)[N], std::size_t p_index) |
| | Safe aliasing constructor for C-array members.
|
| |
| | ~strong_ptr () |
| | Destructor.
|
| |
| strong_ptr & | operator= (strong_ptr const &p_other) noexcept |
| | Copy assignment operator.
|
| |
template<typename U >
requires (std::is_convertible_v<U*, T*>) |
| strong_ptr & | operator= (strong_ptr< U > const &p_other) noexcept |
| | Converting copy assignment operator.
|
| |
| void | swap (strong_ptr &p_other) noexcept |
| | Swap the contents of this strong_ptr with another.
|
| |
|
T & | operator* () &&=delete |
| | Disable dereferencing for r-values (temporaries)
|
| |
|
T * | operator-> () &&=delete |
| | Disable member access for r-values (temporaries)
|
| |
| T & | operator* () const &noexcept |
| | Dereference operator to access the managed object.
|
| |
| T * | operator-> () const &noexcept |
| | Member access operator to access the managed object.
|
| |
| auto | use_count () const noexcept |
| | Get the current reference count.
|
| |
template<typename T>
class atlas::memory::strong_ptr< T >
A non-nullable strong reference counted pointer.
strong_ptr is a smart pointer that maintains shared ownership of an object through a reference count. It is similar to std::shared_ptr but with these key differences:
- Cannot be null - must always point to a valid object
- Can only be created via make_strong_ptr, not from raw pointers
- More memory efficient implementation
Use strong_ptr when you need shared ownership semantics and can guarantee the pointer will never be null. For nullable references, use optional_ptr.
Example usage:
++
auto ptr = hal::make_strong_ptr<my_i2c_driver>(allocator, arg1, arg2);
(*ptr).configure({ .clock_rate = 250_kHz });
ptr->configure({ .clock_rate = 250_kHz });
auto my_imu = hal::make_strong_ptr<my_driver>(allocator, ptr, 0x13);
- Template Parameters
-
| T | The type of the managed object |
Move constructor that intentionally behaves like a copy constructor for safety.
This move constructor deliberately performs a full copy operation rather than transferring ownership. This is a safety feature to prevent potential undefined behavior that could occur if code accidentally accessed a moved-from strong_ptr.
After this operation, both the source and destination objects remain in valid states, and the reference count is incremented by 1. This ensures that even if code incorrectly continues to use the source object after a move, no undefined behavior will occur.
- Parameters
-
| p_other | The strong_ptr to "move" from (actually copied for safety) |
template<typename T >
template<typename U , detail::non_array_like M>
Safe aliasing constructor for object members.
This constructor creates a strong_ptr that points to a member of an object managed by another strong_ptr. The resulting strong_ptr shares ownership with the original strong_ptr, keeping the entire parent object alive.
This version is only enabled for non-array members to prevent potential undefined behavior when accessing array elements directly. Use the array-specific versions instead.
Example usage:
struct container {
component part;
};
auto container_ptr = make_strong_ptr<container>(allocator);
auto component_ptr = strong_ptr<component>(container_ptr,
&container::part);
- Template Parameters
-
| U | Type of the parent object |
| M | Type of the member |
- Parameters
-
| p_other | The strong_ptr to the parent object |
| p_member_ptr | Pointer-to-member identifying which member to reference |
Move assignment operator that behaves like a copy assignment for safety.
This move assignment operator deliberately performs a full copy operation rather than transferring ownership. This is a safety feature to prevent potential undefined behavior that could occur if code accidentally accessed a moved-from strong_ptr.
After this operation, both the source and destination objects remain in valid states, and the reference count is incremented by 1. This ensures that even if code incorrectly continues to use the source object after a move, no undefined behavior will occur.
- Parameters
-
| p_other | The strong_ptr to "move" from (actually copied for safety) |
- Returns
- Reference to *this