Struct Subspace :: sus :: num :: uptr

struct uptr final
{ ... };

A pointer-sized unsigned integer.

This type is capable of holding a pointer, and is convertible to and from pointers. It is typically the same size as usize but it can be larger when pointers include additional bits that the address.

Constructing a uptr

See with_addr for constructing uptr with an address from another uptr.

If pointers contain additional metadata beyond an address, the with_addr method copies the metadata from the original uptr to the newly produced uptr. Otherwise, constructing a uptr from an integer can produce a pointer with invalid (empty) metadata and dereferencing such a pointer would be invalid.

To explicitly construct a uptr with empty metadata, use uptr().with_addr(address).

See the namespace level documentation for more.

Static Data Members

static const u32 BITS

The size of and uptr in bits.

static const uptr MAX_ADDR

The largest address, the same value as usize::MAX but represented as a uptr.

The largest value that can be represented by an uptr, if the size of a pointer is larger than the size of an address, this value will be larger than MAX_ADDR and will always be the maximum value for the integer type.

static const unsigned long MAX_PRIMITIVE

The largest value that can be represented by an uptr, as a native C++ primitive.

static const uptr MIN

The smallest value that can be represented by an uptr.

static const unsigned long MIN_PRIMITIVE

The smallest value that can be represented by an uptr, as a native C++ primitive.

Static Methods

template <class U>
uptr(U v)
requires
sus::num::Unsigned<U>
::sus::mem::size_of<U>() == ::sus::mem::size_of<_primitive>()

Construction from unsigned types of the same size as a pointer.

The construction of a uptr from an integer must be explicit, unlike for other integer types.

uptr(std::same_as<std::nullptr_t> auto)

Construction from a null pointer.

This produces the same value as the default constructor.

Implementation notes

The function receives std::same_as<nullptr_t> to avoid implicit conversions from integer types on some compilers (like GCC 13).

template <class T>
uptr(T* v)

Construction from a pointer.

Default constructor, which sets the integer to 0.

Satisfies the Default concept.

template <class P>
uptr(P v)
requires
sus::num::UnsignedPrimitiveInteger<P>
::sus::mem::size_of<P>() == ::sus::mem::size_of<_primitive>()

Construction from unsigned primitive types the same size as a pointer.

The construction of a uptr from a primitive integer must be explicit, unlike for other integer types.

template <class U>
static auto from(U* u) -> uptr

Constructs a uptr from a pointer.

template <class U>
static auto from(U u) -> uptr
requires
sus::num::Unsigned<U>
::sus::mem::size_of<U>() == ::sus::mem::size_of<_primitive>()

Constructs a uptr from an unsigned integer type (u8, u16, u32, etc) with the same size as a pointer.

template <class U>
static auto from(U u) -> uptr
requires
sus::num::UnsignedPrimitiveInteger<U>
::sus::mem::size_of<U>() == ::sus::mem::size_of<_primitive>()

Constructs a uptr from an unsigned primitive integer type (unsigned int, unsigned long, etc.) with the same size as a pointer.

static auto from_be(const uptr& x) -> uptr

Converts an integer from big endian to the target's endianness.

On big endian this is a no-op. On little endian the bytes are swapped.

static auto from_be_bytes(const sus::collections::Array<u8, ::sus::mem::size_of<_primitive>()>& bytes) -> uptr

Create an integer value from its representation as a byte array in big endian.

static auto from_le(const uptr& x) -> uptr

Converts an integer from little endian to the target's endianness.

On little endian this is a no-op. On big endian the bytes are swapped.

static auto from_le_bytes(const sus::collections::Array<u8, ::sus::mem::size_of<_primitive>()>& bytes) -> uptr

Create an integer value from its representation as a byte array in little endian.

static auto from_ne_bytes(const sus::collections::Array<u8, ::sus::mem::size_of<_primitive>()>& bytes) -> uptr

Create an integer value from its memory representation as a byte array in native endianness.

As the target platform's native endianness is used, portable code likely wants to use from_be_bytes() or from_le_bytes(), as appropriate instead.

static auto from_product(Iterator<uptr> auto&& it) -> uptr
requires
sus::mem::IsMoveRef<decltype(it)>

Constructs a uptr from an Iterator by computing the product of all elements in the iterator.

This method should rarely be called directly, as it is used to satisfy the Product concept so that Iterator::product can be called for iterators over uptr.

To handle overflow without panicing, instead of iter.product(), use iter.product<OverflowInteger<uptr>>().

Panics

This method will panic if the product of all values overflows and overflow checks are enabled (they are by default) and it will wrap if overflow checks are disabled (not the default).

See overflow checks for controlling this behaviour.

static auto from_sum(Iterator<uptr> auto&& it) -> uptr
requires
sus::mem::IsMoveRef<decltype(it)>

Constructs a uptr from an Iterator by computing the sum of all elements in the itertor.

This method should rarely be called directly, as it is used to satisfy the Sum concept so that Iterator::sum can be called for iterators over uptr.

To handle overflow without panicing, instead of iter.sum(), use iter.sum<OverflowInteger<uptr>>().

Panics

This method will panic if the sum of all values overflows if overflow checks are enabled (they are by default) and will wrap if overflow checks are disabled (not the default).

See overflow checks for controlling this behaviour.

template <class U>
static auto try_from(U* u) -> sus::result::Result<uptr, TryFromIntError>

Tries to construct a uptr from a pointer.

This operation can not fail, so it always returns success.

template <class U>
static auto try_from(U u) -> sus::result::Result<uptr, TryFromIntError>
requires
sus::num::Unsigned<U>
::sus::mem::size_of<U>() == ::sus::mem::size_of<_primitive>()

Tries to construct a uptr from an unsigned integer type (u8, u16, u32, etc.) with the same size as a pointer.

As the input has the same size, this function can not return an error.

template <class U>
static auto try_from(U u) -> sus::result::Result<uptr, TryFromIntError>
requires
sus::num::UnsignedPrimitiveInteger<U>
::sus::mem::size_of<U>() == ::sus::mem::size_of<_primitive>()

Construct a uptr from an unsigned primitive integer type (unsigned int, unsigned long, etc.) with the same size as a pointer.

As the input has the same size, this function can not return an error.

Methods

auto abs_diff(uptr other) const& -> uptr

Computes the absolute difference between self and other.

auto addr() const& -> usize

Returns the address portion of the pointer.

In most systems the address is the entire pointer, but in cases where the pointer is larger, this returns the low bits of the pointer up to the size of an address.

auto as_mut_ptr() & -> sus::num::__private::ptr_type::unsigned_type*

Returns a mutable pointer to the underlying C++ primitive value type.

This allows Subspace numerics be used with APIs that expect a pointer to a C++ primitive type.

auto as_ptr() const& -> const sus::num::__private::ptr_type::unsigned_type*
auto as_ptr() && -> const sus::num::__private::ptr_type::unsigned_type*
deleted

Returns a const pointer to the underlying C++ primitive value type.

This allows Subspace numerics be used with APIs that expect a pointer to a C++ primitive type.

auto checked_add(uptr rhs) const& -> Option<uptr>
template <class U>
auto checked_add(U rhs) const& -> Option<uptr>
requires
UnsignedNumeric<U> || UnsignedPrimitiveInteger<U>
::sus::mem::size_of<U>() <= ::sus::mem::size_of<_primitive>()

Checked integer addition. Computes self + rhs, returning None if overflow occurred.

auto checked_div(uptr rhs) const& -> Option<uptr>
template <class U>
auto checked_div(U rhs) const& -> Option<uptr>
requires
UnsignedNumeric<U> || UnsignedPrimitiveInteger<U>
::sus::mem::size_of<U>() <= ::sus::mem::size_of<_primitive>()

Checked integer division. Computes self / rhs, returning None if rhs == 0.

template <class U>
auto checked_div_euclid(U rhs) const& -> Option<uptr>
requires
UnsignedNumeric<U> || UnsignedPrimitiveInteger<U>
::sus::mem::size_of<U>() <= ::sus::mem::size_of<_primitive>()

Checked Euclidean division. Computes self.div_euclid(rhs), returning None if rhs == 0.

auto checked_log(uptr base) const& -> Option<u32>
template <class U>
auto checked_log(U rhs) const& -> Option<u32>
requires
UnsignedNumeric<U> || UnsignedPrimitiveInteger<U>
::sus::mem::size_of<U>() <= ::sus::mem::size_of<_primitive>()

Returns the logarithm of the number with respect to an arbitrary base, rounded down.

Returns None if the number is zero, or if the base is not at least 2.

This method might not be optimized owing to implementation details; checked_log2 can produce results more efficiently for base 2, and checked_log10 can produce results more efficiently for base 10.

auto checked_log10() const& -> Option<u32>

Returns the base 10 logarithm of the number, rounded down.

Returns None if the number is zero.

auto checked_log2() const& -> Option<u32>

Returns the base 2 logarithm of the number, rounded down.

Returns None if the number is zero.

auto checked_mul(uptr rhs) const& -> Option<uptr>
template <class U>
auto checked_mul(U rhs) const& -> Option<uptr>
requires
UnsignedNumeric<U> || UnsignedPrimitiveInteger<U>
::sus::mem::size_of<U>() <= ::sus::mem::size_of<_primitive>()

Checked integer multiplication. Computes self * rhs, returning None if overflow occurred.

auto checked_neg() const& -> Option<uptr>

Checked negation. Computes -self, returning None unless self == 0.

Note that negating any positive integer will overflow.

template <class U>
auto checked_next_multiple_of(U rhs) const& -> Option<uptr>
requires
UnsignedNumeric<U> || UnsignedPrimitiveInteger<U>
::sus::mem::size_of<U>() <= ::sus::mem::size_of<_primitive>()

Calculates the smallest value greater than or equal to itself that is a multiple of rhs. Returns None if rhs is zero or the operation would result in overflow.

Examples

Basic usage:

sus_check((16_u32).checked_next_multiple_of(8u) == sus::some(16u));
sus_check((23_u32).checked_next_multiple_of(8u) == sus::some(24u));
sus_check((1_u32).checked_next_multiple_of(0u) == sus::none());
sus_check(u32::MAX.checked_next_multiple_of(2u) == sus::none());

Returns the smallest power of two greater than or equal to self.

If the next power of two is greater than the type's maximum value, None is returned, otherwise the power of two is wrapped in Some.

auto checked_pow(u32 rhs) const& -> Option<uptr>

Checked exponentiation. Computes pow, returning None if overflow occurred.

auto checked_rem(uptr rhs) const& -> Option<uptr>
template <class U>
auto checked_rem(U rhs) const& -> Option<uptr>
requires
UnsignedNumeric<U> || UnsignedPrimitiveInteger<U>
::sus::mem::size_of<U>() <= ::sus::mem::size_of<_primitive>()

Checked integer remainder. Computes self % rhs, returning None if rhs == 0.

template <class U>
auto checked_rem_euclid(U rhs) const& -> Option<uptr>
requires
UnsignedNumeric<U> || UnsignedPrimitiveInteger<U>
::sus::mem::size_of<U>() <= ::sus::mem::size_of<_primitive>()

Checked Euclidean modulo. Computes self.rem_euclid(rhs), returning None if rhs == 0.

auto checked_shl(u64 rhs) const& -> Option<uptr>

Checked shift left. Computes self << rhs, returning None if rhs is larger than or equal to the number of bits in self.

auto checked_shr(u64 rhs) const& -> Option<uptr>

Checked shift right. Computes self >> rhs, returning None if rhs is larger than or equal to the number of bits in self.

auto checked_sub(uptr rhs) const& -> Option<uptr>
template <class U>
auto checked_sub(U rhs) const& -> Option<uptr>
requires
UnsignedNumeric<U> || UnsignedPrimitiveInteger<U>
::sus::mem::size_of<U>() <= ::sus::mem::size_of<_primitive>()

Checked integer subtraction. Computes self - rhs, returning None if overflow occurred.

auto count_ones() const& -> u32

Returns the number of ones in the binary representation of the current value.

auto count_zeros() const& -> u32

Returns the number of zeros in the binary representation of the current value.

auto div_ceil(uptr rhs) const& -> uptr
template <class U>
auto div_ceil(U rhs) const& -> uptr
requires
UnsignedNumeric<U> || UnsignedPrimitiveInteger<U>
::sus::mem::size_of<U>() <= ::sus::mem::size_of<_primitive>()

Calculates the quotient of itself and rhs, rounding the result towards positive infinity.

Panics

This function will panic if rhs is 0.

Examples

Basic usage:

sus_check((7_u8).div_ceil(4u) == 2u);
auto div_euclid(uptr rhs) const& -> uptr
template <class U>
auto div_euclid(U rhs) const& -> uptr
requires
UnsignedNumeric<U> || UnsignedPrimitiveInteger<U>
::sus::mem::size_of<U>() <= ::sus::mem::size_of<_primitive>()

Performs Euclidean division.

Since, for the positive integers, all common definitions of division are equal, this is exactly equal to self / rhs.

Panics

This function will panic if rhs is 0.

auto is_power_of_two() const& -> bool

Returns true if and only if self == 2^k for some k.

auto leading_ones() const& -> u32

Returns the number of leading ones in the binary representation of the current value.

auto leading_zeros() const& -> u32

Returns the number of leading zeros in the binary representation of the current value.

auto log(uptr base) const& -> u32
template <class U>
auto log(U rhs) const& -> u32
requires
UnsignedNumeric<U> || UnsignedPrimitiveInteger<U>
::sus::mem::size_of<U>() <= ::sus::mem::size_of<_primitive>()

Returns the logarithm of the number with respect to an arbitrary base, rounded down.

This method might not be optimized owing to implementation details; log2 can produce results more efficiently for base 2, and log10 can produce results more efficiently for base 10.

Panics

This function will panic if the current value is zero, or if base is less than 2.

auto log10() const& -> u32

Returns the base 10 logarithm of the number, rounded down.

Panics

When the number is zero the function will panic.

auto log2() const& -> u32

Returns the base 2 logarithm of the number, rounded down.

Panics

When the number is zero the function will panic.

auto next_multiple_of(uptr rhs) const& -> uptr
template <class U>
auto next_multiple_of(U rhs) const& -> uptr
requires
UnsignedNumeric<U> || UnsignedPrimitiveInteger<U>
::sus::mem::size_of<U>() <= ::sus::mem::size_of<_primitive>()

Calculates the smallest value greater than or equal to itself that is a multiple of rhs.

Panics

This function will panic if rhs is zero.

Overflow behavior

On overflow, this function will panic if overflow checks are enabled (they are by default) and wrap if overflow checks are disabled (not the default).

Examples

Basic usage:

sus_check((16_u32).next_multiple_of(8u) == 16u);
sus_check((23_u32).next_multiple_of(8u) == 24u);
auto next_power_of_two() const& -> uptr

Returns the smallest power of two greater than or equal to self.

Panics

The function panics when the return value overflows (i.e., self > (1u << (uptr::BITS - 1u))) if overflow checks are enabled (they are by default) and will wrap if overflow checks are disabled (not the default).

See overflow checks for controlling this behaviour.

auto overflowing_add(uptr rhs) const& -> sus::tuple_type::Tuple<uptr, bool>
template <class U>
auto overflowing_add(U rhs) const& -> sus::tuple_type::Tuple<uptr, bool>
requires
UnsignedNumeric<U> || UnsignedPrimitiveInteger<U>
::sus::mem::size_of<U>() <= ::sus::mem::size_of<_primitive>()

Calculates self + rhs.

Returns a tuple of the addition along with a boolean indicating whether an arithmetic overflow would occur. If an overflow would have occurred then the wrapped value is returned.

auto overflowing_div(uptr rhs) const& -> sus::tuple_type::Tuple<uptr, bool>
template <class U>
auto overflowing_div(U rhs) const& -> sus::tuple_type::Tuple<uptr, bool>
requires
UnsignedNumeric<U> || UnsignedPrimitiveInteger<U>
::sus::mem::size_of<U>() <= ::sus::mem::size_of<_primitive>()

Calculates the divisor when self is divided by rhs.

Returns a tuple of the divisor along with a boolean indicating whether an arithmetic overflow would occur. Note that for unsigned integers overflow never occurs, so the second value is always false.

Panics

This function will panic if rhs is 0.

auto overflowing_div_euclid(uptr rhs) const& -> sus::tuple_type::Tuple<uptr, bool>
template <class U>
auto overflowing_div_euclid(U rhs) const& -> sus::tuple_type::Tuple<uptr, bool>
requires
UnsignedNumeric<U> || UnsignedPrimitiveInteger<U>
::sus::mem::size_of<U>() <= ::sus::mem::size_of<_primitive>()

Calculates the quotient of Euclidean division self.div_euclid(rhs).

Returns a tuple of the divisor along with a boolean indicating whether an arithmetic overflow would occur. Note that for unsigned integers overflow never occurs, so the second value is always false. Since, for the positive integers, all common definitions of division are equal, this is exactly equal to self.overflowing_div(rhs).

Panics

This function will panic if rhs is 0.

auto overflowing_mul(uptr rhs) const& -> sus::tuple_type::Tuple<uptr, bool>
template <class U>
auto overflowing_mul(U rhs) const& -> sus::tuple_type::Tuple<uptr, bool>
requires
UnsignedNumeric<U> || UnsignedPrimitiveInteger<U>
::sus::mem::size_of<U>() <= ::sus::mem::size_of<_primitive>()

Calculates the multiplication of self and rhs.

Returns a tuple of the multiplication along with a boolean indicating whether an arithmetic overflow would occur. If an overflow would have occurred then the wrapped value is returned.

auto overflowing_neg() const& -> sus::tuple_type::Tuple<uptr, bool>

Negates self in an overflowing fashion.

Returns ~self + 1 using wrapping operations to return the value that represents the negation of this unsigned value. Note that for positive unsigned values overflow always occurs, but negating 0 does not overflow.

auto overflowing_pow(u32 exp) const& -> sus::tuple_type::Tuple<uptr, bool>

Raises self to the power of exp, using exponentiation by squaring.

Returns a tuple of the exponentiation along with a bool indicating whether an overflow happened.

auto overflowing_rem(uptr rhs) const& -> sus::tuple_type::Tuple<uptr, bool>
template <class U>
auto overflowing_rem(U rhs) const& -> sus::tuple_type::Tuple<uptr, bool>
requires
UnsignedNumeric<U> || UnsignedPrimitiveInteger<U>
::sus::mem::size_of<U>() <= ::sus::mem::size_of<_primitive>()

Calculates the remainder when self is divided by rhs.

Returns a tuple of the remainder after dividing along with a boolean indicating whether an arithmetic overflow would occur. Note that for unsigned integers overflow never occurs, so the second value is always false.

Panics

This function will panic if rhs is 0.

auto overflowing_rem_euclid(uptr rhs) const& -> sus::tuple_type::Tuple<uptr, bool>
template <class U>
auto overflowing_rem_euclid(U rhs) const& -> sus::tuple_type::Tuple<uptr, bool>
requires
UnsignedNumeric<U> || UnsignedPrimitiveInteger<U>
::sus::mem::size_of<U>() <= ::sus::mem::size_of<_primitive>()

Calculates the remainder self.rem_euclid(rhs) as if by Euclidean division.

Returns a tuple of the modulo after dividing along with a boolean indicating whether an arithmetic overflow would occur. Note that for unsigned integers overflow never occurs, so the second value is always false. Since, for the positive integers, all common definitions of division are equal, this operation is exactly equal to self.overflowing_rem(rhs).

Panics

This function will panic if rhs is 0.

auto overflowing_shl(u64 rhs) const& -> sus::tuple_type::Tuple<uptr, bool>

Shifts self left by rhs bits.

Returns a tuple of the shifted version of self along with a boolean indicating whether the shift value was larger than or equal to the number of bits. If the shift value is too large, then value is masked by (N-1) where N is the number of bits, and this value is then used to perform the shift.

auto overflowing_shr(u64 rhs) const& -> sus::tuple_type::Tuple<uptr, bool>

Shifts self right by rhs bits.

Returns a tuple of the shifted version of self along with a boolean indicating whether the shift value was larger than or equal to the number of bits. If the shift value is too large, then value is masked by (N-1) where N is the number of bits, and this value is then used to perform the shift.

auto overflowing_sub(uptr rhs) const& -> sus::tuple_type::Tuple<uptr, bool>
template <class U>
auto overflowing_sub(U rhs) const& -> sus::tuple_type::Tuple<uptr, bool>
requires
UnsignedNumeric<U> || UnsignedPrimitiveInteger<U>
::sus::mem::size_of<U>() <= ::sus::mem::size_of<_primitive>()

Calculates self - rhs.

Returns a tuple of the subtraction along with a boolean indicating whether an arithmetic overflow would occur. If an overflow would have occurred then the wrapped value is returned.

auto pow(u32 rhs) const& -> uptr

Raises self to the power of exp, using exponentiation by squaring.

Panics

This function will panic on overflow if overflow checks are enabled (they are by default) and will wrap if overflow checks are disabled (not the default).

See overflow checks for controlling this behaviour.

auto rem_euclid(uptr rhs) const& -> uptr
template <class U>
auto rem_euclid(U rhs) const& -> uptr
requires
UnsignedNumeric<U> || UnsignedPrimitiveInteger<U>
::sus::mem::size_of<U>() <= ::sus::mem::size_of<_primitive>()

Calculates the least remainder of self (mod rhs).

Since, for the positive integers, all common definitions of division are equal, this is exactly equal to self % rhs.

Panics

This function will panic if rhs is 0.

auto reverse_bits() const& -> uptr

Reverses the order of bits in the integer. The least significant bit becomes the most significant bit, second least-significant bit becomes second most-significant bit, etc.

auto rotate_left(u64 n) const& -> uptr

Shifts the bits to the left by a specified amount, n, wrapping the truncated bits to the end of the resulting integer.

Please note this isn't the same operation as the << shifting operator!

auto rotate_right(u64 n) const& -> uptr

Shifts the bits to the right by a specified amount, n, wrapping the truncated bits to the beginning of the resulting integer.

Please note this isn't the same operation as the >> shifting operator!

auto saturating_add(uptr rhs) const& -> uptr
template <class U>
auto saturating_add(U rhs) const& -> uptr
requires
UnsignedNumeric<U> || UnsignedPrimitiveInteger<U>
::sus::mem::size_of<U>() <= ::sus::mem::size_of<_primitive>()

Saturating integer addition. Computes self + rhs, saturating at the numeric bounds instead of overflowing.

auto saturating_div(uptr rhs) const& -> uptr
template <class U>
auto saturating_div(U rhs) const& -> uptr
requires
UnsignedNumeric<U> || UnsignedPrimitiveInteger<U>
::sus::mem::size_of<U>() <= ::sus::mem::size_of<_primitive>()

Saturating integer division. Computes self / rhs, saturating at the numeric bounds instead of overflowing. Note that for unsigned integers overflow never occurs, so the value will always be strictly the result of division.

Panics

This function will panic if rhs is 0.

auto saturating_mul(uptr rhs) const& -> uptr
template <class U>
auto saturating_mul(U rhs) const& -> uptr
requires
UnsignedNumeric<U> || UnsignedPrimitiveInteger<U>
::sus::mem::size_of<U>() <= ::sus::mem::size_of<_primitive>()

Saturating integer multiplication. Computes self * rhs, saturating at the numeric bounds instead of overflowing.

auto saturating_sub(uptr rhs) const& -> uptr
template <class U>
auto saturating_sub(U rhs) const& -> uptr
requires
UnsignedNumeric<U> || UnsignedPrimitiveInteger<U>
::sus::mem::size_of<U>() <= ::sus::mem::size_of<_primitive>()

Saturating integer subtraction. Computes self - rhs, saturating at the numeric bounds instead of overflowing.

auto swap_bytes() const& -> uptr

Reverses the byte order of the integer.

auto to_be() const& -> uptr

Converts self to big endian from the target's endianness.

On big endian this is a no-op. On little endian the bytes are swapped.

auto to_be_bytes() const& -> sus::collections::Array<u8, ::sus::mem::size_of<_primitive>()>

Return the memory representation of this integer as a byte array in big-endian (network) byte order.

auto to_le() const& -> uptr

Converts self to little endian from the target's endianness.

On little endian this is a no-op. On big endian the bytes are swapped.

auto to_le_bytes() const& -> sus::collections::Array<u8, ::sus::mem::size_of<_primitive>()>

Return the memory representation of this integer as a byte array in little-endian byte order.

auto to_ne_bytes() const& -> sus::collections::Array<u8, ::sus::mem::size_of<_primitive>()>

Return the memory representation of this integer as a byte array in native byte order.

As the target platform's native endianness is used, portable code should use to_be_bytes() or to_le_bytes(), as appropriate, instead.

auto trailing_ones() const& -> u32

Returns the number of trailing ones in the binary representation of the current value.

auto trailing_zeros() const& -> u32

Returns the number of trailing zeros in the binary representation of the current value.

template <class U>
auto unchecked_add(UnsafeFnMarker, U rhs) const& -> uptr
requires
UnsignedNumeric<U> || UnsignedPrimitiveInteger<U>
::sus::mem::size_of<U>() <= ::sus::mem::size_of<_primitive>()

Unchecked integer addition. Computes self + rhs, assuming overflow cannot occur.

Safety

This function is allowed to result in undefined behavior when self + rhs > MAX_BIT_PATTERN or self + rhs < MIN, i.e. when checked_add would return None.

template <class U>
auto unchecked_mul(UnsafeFnMarker, U rhs) const& -> uptr
requires
UnsignedNumeric<U> || UnsignedPrimitiveInteger<U>
::sus::mem::size_of<U>() <= ::sus::mem::size_of<_primitive>()

Unchecked integer multiplication. Computes self * rhs, assuming overflow cannot occur.

Safety

This function is allowed to result in undefined behavior when self * rhs > MAX_BIT_PATTERN or self * rhs < MIN, i.e. when checked_mul would return None.

template <class U>
auto unchecked_sub(UnsafeFnMarker, U rhs) const& -> uptr
requires
UnsignedNumeric<U> || UnsignedPrimitiveInteger<U>
::sus::mem::size_of<U>() <= ::sus::mem::size_of<_primitive>()

Unchecked integer subtraction. Computes self - rhs, assuming overflow cannot occur.

Safety

This function is allowed to result in undefined behavior when self - rhs > MAX_BIT_PATTERN or self - rhs < MIN, i.e. when checked_sub would return None.

auto with_addr(usize addr) const& -> uptr

Creates a new pointer with the given address.

This converts the address into a pointer-sized integer, but copies the address-space and provenance of the current uptr's value to the new pointer. This allows us to dynamically preserve and propagate this important information in a way that is otherwise impossible with a cast.

auto wrapping_add(uptr rhs) const& -> uptr
template <class U>
auto wrapping_add(U rhs) const& -> uptr
requires
UnsignedNumeric<U> || UnsignedPrimitiveInteger<U>
::sus::mem::size_of<U>() <= ::sus::mem::size_of<_primitive>()

Wrapping (modular) addition. Computes self + rhs, wrapping around at the boundary of the type.

auto wrapping_div(uptr rhs) const& -> uptr
template <class U>
auto wrapping_div(U rhs) const& -> uptr
requires
UnsignedNumeric<U> || UnsignedPrimitiveInteger<U>
::sus::mem::size_of<U>() <= ::sus::mem::size_of<_primitive>()

Wrapping (modular) division. Computes self / rhs. Wrapped division on unsigned types is just normal division. There's no way wrapping could ever happen. This function exists, so that all operations are accounted for in the wrapping operations.

Panics

This function will panic if rhs is 0.

auto wrapping_div_euclid(uptr rhs) const& -> uptr
template <class U>
auto wrapping_div_euclid(U rhs) const& -> uptr
requires
UnsignedNumeric<U> || UnsignedPrimitiveInteger<U>
::sus::mem::size_of<U>() <= ::sus::mem::size_of<_primitive>()

Wrapping Euclidean division. Computes self.div_euclid(rhs). Wrapped division on unsigned types is just normal division.

There's no way wrapping could ever happen. This function exists so that all operations are accounted for in the wrapping operations. Since, for the positive integers, all common definitions of division are equal, this is exactly equal to self.wrapping_div(rhs).

Panics

This function will panic if rhs is 0.

auto wrapping_mul(uptr rhs) const& -> uptr
template <class U>
auto wrapping_mul(U rhs) const& -> uptr
requires
UnsignedNumeric<U> || UnsignedPrimitiveInteger<U>
::sus::mem::size_of<U>() <= ::sus::mem::size_of<_primitive>()

Wrapping (modular) multiplication. Computes self * rhs, wrapping around at the boundary of the type.

auto wrapping_neg() const& -> uptr

Wrapping (modular) negation. Computes -self, wrapping around at the boundary of the type.

Since unsigned types do not have negative equivalents all applications of this function will wrap (except for -0). For values smaller than the corresponding signed type's maximum the result is the same as casting the corresponding signed value. Any larger values are equivalent to MAX + 1 - (val - MAX - 1) where MAX is the corresponding signed type's maximum.

Returns the smallest power of two greater than or equal to self.

If the next power of two is greater than the type's maximum value, the return value is wrapped to 0.

auto wrapping_pow(u32 exp) const& -> uptr

Wrapping (modular) exponentiation. Computes pow, wrapping around at the boundary of the type.

auto wrapping_rem(uptr rhs) const& -> uptr
template <class U>
auto wrapping_rem(U rhs) const& -> uptr
requires
UnsignedNumeric<U> || UnsignedPrimitiveInteger<U>
::sus::mem::size_of<U>() <= ::sus::mem::size_of<_primitive>()

Wrapping (modular) remainder. Computes self % rhs. Wrapped remainder calculation on unsigned types is just the regular remainder calculation.

There's no way wrapping could ever happen. This function exists, so that all operations are accounted for in the wrapping operations.

Panics

This function will panic if rhs is 0.

auto wrapping_rem_euclid(uptr rhs) const& -> uptr
template <class U>
auto wrapping_rem_euclid(U rhs) const& -> uptr
requires
UnsignedNumeric<U> || UnsignedPrimitiveInteger<U>
::sus::mem::size_of<U>() <= ::sus::mem::size_of<_primitive>()

Wrapping Euclidean modulo. Computes self.rem_euclid(rhs). Wrapped modulo calculation on unsigned types is just the regular remainder calculation.

There’s no way wrapping could ever happen. This function exists, so that all operations are accounted for in the wrapping operations. Since, for the positive integers, all common definitions of division are equal, this is exactly equal to self.wrapping_rem(rhs).

Panics

This function will panic if rhs is 0.

auto wrapping_shl(u64 rhs) const& -> uptr

Panic-free bitwise shift-left; yields self << mask(rhs), where mask removes any high-order bits of rhs that would cause the shift to exceed the bitwidth of the type.

Note that this is not the same as a rotate-left; the RHS of a wrapping shift-left is restricted to the range of the type, rather than the bits shifted out of the LHS being returned to the other end. The Subspace integer types all implement a rotate_left function, which may be what you want instead.

auto wrapping_shr(u64 rhs) const& -> uptr

Panic-free bitwise shift-right; yields self >> mask(rhs), where mask removes any high-order bits of rhs that would cause the shift to exceed the bitwidth of the type.

Note that this is not the same as a rotate-right; the RHS of a wrapping shift-right is restricted to the range of the type, rather than the bits shifted out of the LHS being returned to the other end. The Subspace integer types all implement a rotate_right function, which may be what you want instead.

auto wrapping_sub(uptr rhs) const& -> uptr
template <class U>
auto wrapping_sub(U rhs) const& -> uptr
requires
UnsignedNumeric<U> || UnsignedPrimitiveInteger<U>
::sus::mem::size_of<U>() <= ::sus::mem::size_of<_primitive>()

Wrapping (modular) subtraction. Computes self - rhs, wrapping around at the boundary of the type.

Conversions

template <class U>
operator U() const
requires
std::same_as<U, uintptr_t>

Conversion from the numeric type to a C++ primitive type.

This converts to uintptr_t but not to other signed or unsigned integer types. Note that the C++ standard library may alias uintptr_t with uint32_t or uint64_t which would then allow that specific conversion as well.

auto d = uintptr_t{uptr()};  // Compiles.
auto e = uintptr_t(uptr());  // Compiles.
uintptr_t f = uptr();  // Compiles.

auto d = int64_t{uptr()};  // Does not compile.
auto e = int64_t(uptr());  // Does not compile.
int64_t f = uptr();  // Does not compile.

Potentially-lossy type conversions can be forced through the Cast concept, such as sus::cast<uint32_t>(uptr()) or sus::cast<int32_t>(uptr()), or even sus::cast<u32>(uptr()).

Operators

auto operator%=(uptr r) & -> void
auto operator%=(sus::num::__private::ptr_type::pointer_sized_type r) & -> void

Assigns the remainder of dividing itself by r.

Satisfies the RemAssign<uptr> concept.

Panics

This operation will panic if r is 0.

auto operator&=(uptr r) & -> void
auto operator&=(sus::num::__private::ptr_type::pointer_sized_type r) & -> void

Assigns the bitwise AND of itself and r.

Satisfies the BitAndAssign<uptr> concept.

auto operator*=(uptr r) & -> void
auto operator*=(sus::num::__private::ptr_type::pointer_sized_type r) & -> void

Multiplies itself by r.

Satisfies the MulAssign<uptr> concept.

Panics

This operation will panic on overflow if overflow checks are enabled (they are by default) and will wrap if overflow checks are disabled (not the default).

See overflow checks for controlling this behaviour.

auto operator+=(uptr r) & -> void
auto operator+=(sus::num::__private::ptr_type::pointer_sized_type r) & -> void

Adds r to itself.

Satisfies the AddAssign<uptr> concept.

Panics

This operation will panic on overflow if overflow checks are enabled (they are by default) and will wrap if overflow checks are disabled (not the default).

See overflow checks for controlling this behaviour.

auto operator-=(uptr r) & -> void
auto operator-=(sus::num::__private::ptr_type::pointer_sized_type r) & -> void

Subtracts r from itself.

Satisfies the SubAssign<uptr> concept.

Panics

This operation will panic on overflow if overflow checks are enabled (they are by default) and will wrap if overflow checks are disabled (not the default).

See overflow checks for controlling this behaviour.

auto operator/=(uptr r) & -> void
auto operator/=(sus::num::__private::ptr_type::pointer_sized_type r) & -> void

Divides itself by r.

Satisfies the DivAssign<uptr> concept.

Panics

This operation will panic if r is 0.

auto operator<<=(u64 r) & -> void

Shifts itself left by r bits.

Panics

This function will panic when r is not less than the number of bits in uptr if overflow checks are enabled (they are by default) and will perform a wrapping shift if overflow checks are disabled (not the default).

See overflow checks for controlling this behaviour.

Satisfies the ShlAssign<uptr> concept.

template <class T>
auto operator=(T* v) -> uptr&

Assignment from a pointer.

auto operator=(std::same_as<std::nullptr_t> auto) -> uptr&

Assignment from a null pointer.

This sets the uptr to the same value as the default constructor.

Implementation notes

The function receives std::same_as<nullptr_t> to avoid implicit conversions from integer types on some compilers (like GCC 13).

template <class U>
auto operator=(U v) -> uptr&
requires
sus::num::Unsigned<U>
::sus::mem::size_of<U>() == ::sus::mem::size_of<_primitive>()

Assignment from unsigned types with the same size as a pointer.

template <class P>
auto operator=(P v) -> uptr&
requires
sus::num::UnsignedPrimitiveInteger<P>
::sus::mem::size_of<P>() == ::sus::mem::size_of<_primitive>()

Assignment from unsigned primitive types with the same size as a pointer.

auto operator>>=(u64 r) & -> void

Shifts itself right by r bits.

Satisfies the ShrAssign<uptr> concept.

Panics

This function will panic when r is not less than the number of bits in uptr if overflow checks are enabled (they are by default) and will perform a wrapping shift if overflow checks are disabled (not the default).

See overflow checks for controlling this behaviour.

auto operator^=(uptr r) & -> void
auto operator^=(sus::num::__private::ptr_type::pointer_sized_type r) & -> void

Assigns the bitwise XOR of itself and r.

Satisfies the BitXorAssign<uptr> concept.

auto operator|=(uptr r) & -> void
auto operator|=(sus::num::__private::ptr_type::pointer_sized_type r) & -> void

Assigns the bitwise OR of itself and r.

Satisfies the BitOrAssign<uptr> concept.

auto operator~() const& -> uptr

Computes the bitwise complement (bitwise inverse) of the current value.

Satisfies the BitNot<uptr> concept.

Data Members

sus::num::__private::ptr_type::unsigned_type primitive_value

The inner primitive value. Prefer to cast to the desired primitive type, such as with uint32_t{n} for a numeric value n.