module
SmartPtrsSmartPtrs
provides utilities for implementing and working with Cnx smart pointers
Defines
- #define ptr(self)
- Returns a pointer to the managed object of a Cnx smart pointer.
- #define ptr_const(self)
- Returns a pointer-to-const to the managed object of a Cnx smart pointer.
- #define ptr_mut(self)
- Returns a pointer-to-non-const to the managed object of a Cnx smart pointer.
- #define ptr_move(self)
- Moves
self
into the assigned-to or bound-to variable/parameter/etc. - #define CnxDeleter(T, ...)
- The function type (with optional name, for use in typedefs) of a deleter function used in smart pointer templates.
Define documentation
#define ptr(self)
Returns a pointer to the managed object of a Cnx smart pointer.
Parameters | |
---|---|
self | - The smart pointer to get the pointer from |
Returns | const correct pointer to the object managed by self |
This is const correct:
- If
self
is const, this will return a pointer-to-const of the managed object. - Otherwise, this will return a "normal" pointer to the managed object. If you want to explicitly get a pointer-to-const or pointer-to-not-const, use
ptr_const
orptr_mut
, respectively.
#define ptr_const(self)
Returns a pointer-to-const to the managed object of a Cnx smart pointer.
Parameters | |
---|---|
self | - The smart pointer to get the pointer from |
Returns | pointer-to-const to the object managed by self |
#define ptr_mut(self)
Returns a pointer-to-non-const to the managed object of a Cnx smart pointer.
Parameters | |
---|---|
self | - The smart pointer to get the pointer from |
Returns | pointer-to-non-const to the object managed by self |
#define ptr_move(self)
Moves self
into the assigned-to or bound-to variable/parameter/etc.
Parameters | |
---|---|
self | - The smart pointer to move |
Returns | the moved value |
This is almost equivalent to move
provided in Def
, but ensures that the pointer to the managed object in the moved-from value is set to the correct nullptr
constant for the platform, for cases where the platform's nullptr
(NULL
) constant is not zero. If your target platform(s)'s nullptr
constant is guaranteed to be zero, you can safely use move
instead.
#define CnxDeleter(T, ...)
The function type (with optional name, for use in typedefs) of a deleter function used in smart pointer templates.
Given an instance of T
, t
, the signature is: void (*name)(Y* restrict to_deleter, CnxAllocator allocator);
where Y
is either:
typeof(t)
ifT
is NOT an array type (e.g.int
,usize
,CnxVector(i32)
)typeof(t[0]) if
T__IS__ an array type (e.g. a typedef to
int[]or
usize[]`)