A nullable pointer to a T inside Cage, stored in 4 bytes. Use it as ptr<T> or strict_ptr<T>, declared below.
ptr converts implicitly from and to T*, so it can replace a raw pointer member with few other changes. strict_ptr (Strict = true) only converts to T* implicitly: compressing a T* takes an explicit constructor call, so a pointer from outside the cage cannot slip in unnoticed, and mixing it with T* in ?: is not ambiguous. Constructing either from a pointer outside the cage is a bug (checked by assertions in debug builds, or always with CPTR_CHECKED).
| Name | Description |
|---|---|
cage_type | The cage the pointer is compressed against. |
difference_type | The signed distance between two pointers, in elements. Together with the iterator types below, it lets ptr serve as an allocator's pointer type, which must be a random access iterator. |
element_type | The type pointed to. |
iterator_category | ptr is a random access iterator for code that reads std::iterator_traits... |
iterator_concept | ...and a contiguous iterator for the C++20 iterator concepts, so that algorithms such as std::copy over a range of ptr lower to memmove. |
pointer | The raw pointer type, as for an iterator. |
rebind | The same kind of pointer to a U, for std::pointer_traits. |
reference | The type operator* returns, as for an iterator. |
value_type | The pointee type without cv-qualifiers, as for an iterator. |
| Name | Description |
|---|---|
basic_ptr [constructor] | Constructors |
operator= | Assignment operators |
bits | The compressed representation, e.g. for packing it with other data. Zero is null; otherwise it is the offset from the cage base, shifted right by Cage::shift. |
get | The raw pointer, or nullptr: an add plus the null check, which clang turns into a conditional move and GCC usually into a branch. Constant-evaluable when null, since that does not need the cage base. |
operator* | The object pointed to. Like operator->, it skips the null check, so the pointer must not be null. |
operator++ | Advance by one element. |
operator+= | Advance by n elements. |
operator-- | Go back by one element. |
operator-= | Go back by n elements. |
operator-> | Member access: a single add. Dereferencing null is undefined, so this skips the null check: on a null ptr it returns the cage base, not nullptr, and an access through it faults because the cage's first span is never committed. Use get() when the pointer may be null. |
operator[] | Element i counting from this one, as for a raw pointer. |
operator T* | Converts implicitly to the raw pointer, so a ptr can be passed wherever a T* is expected. |
operator bool | True unless null. |
| Name | Description |
|---|---|
from_bits | The pointer whose bits() are bits. Only pass bits() of a pointer into the same cage: bits from another cage (or another cage type with the same T) decode to an unrelated address in this one, and nothing checks it. |
pointer_to | For std::pointer_traits, so ptr can serve as an allocator's pointer type. |
| Name | Description |
|---|---|
cptr::operator- | The number of elements between a raw pointer and this pointer into the same array, as a - get(). |
cptr::operator- | The number of elements between this pointer and a raw pointer into the same array, as get() - b. |
cptr::operator<=> | Orders a ptr and a strict_ptr to the same type by address. |
cptr::operator== | Same address, between a ptr and a strict_ptr to the same type, which would otherwise be ambiguous: each converts to the other. |
cptr::operator<=> | Orders like get() <=> b through std::compare_three_way, so null orders first and unrelated pointers get a total order. |
cptr::operator<=> | All pointers share the cage base, so offsets order like addresses. Null orders first. |
cptr::operator== | Same address as the raw pointer b, as get() == b. Takes any U* that converts implicitly to T*. |
cptr::operator== | True if null, for a literal 0 or NULL. Any other integer does not compile. |
cptr::operator== | True if null. A template, as are the overloads below, so that only one of them takes a literal 0. |
cptr::operator== | Same address. Compares the offsets, without touching the cage base. |
cptr::operator- | The number of elements between two pointers into the same array. |
cptr::operator- | Subtraction operator |
cptr::operator+ | Addition operator |
cptr::operator+ | The pointer n elements further on. |
| Name | Description |
|---|---|
destroy | Destroy and free an object created by make(), as delete does; null is a no-op. A pointer to const works, as for delete. |
destroy_array | Destroy and free n elements created by make_array(n). n must be the count passed to make_array(), and p the pointer it returned (not a pointer to a base class: as for delete[], that is undefined). Null is a no-op. |