class NonNull

Declaration

template <class T>
class NonNull { /* full declaration omitted */ };

Description

A pointer wrapper which holds a never-null pointer. A `NonNull` can not be implicitly created from an array, as that would throw away the length information. Explicitly cast to a pointer to use NonNull with an array. The `NonNull` type is trivially copyable and moveable. `NonNull` satisifes the [`NeverValueField`]($sus::mem::NeverValueField), so [`Option <NonNull <T >>`]($sus::option::Option) has the same size as `NonNull`, similar to [`Option <T & >`]($sus::option::Option). TODO: Make a NonNullArray type? https://godbolt.org/z/3vW3xsz5h

Declared at: sus/ptr/nonnull.h:46

Templates

T

Method Overview

  • public constexpr NonNull<T>(T & t) noexcept
  • public inline constexpr T & as_mut() noexcept
  • public inline constexpr T * as_mut_ptr() noexcept
  • public inline constexpr const T * as_ptr() const noexcept
  • public inline constexpr const T & as_ref() const noexcept
  • public template <class U>NonNull<U> cast() const noexcept
  • public template <class U>NonNull<U> downcast(::sus::marker::UnsafeFnMarker) const noexcept
  • public static inline constexpr NonNull<T> from(T & t) noexcept
  • public template <class U, size_t N>static inline constexpr NonNull<T> from(U (&)[N] t)
  • public template <class U>static inline constexpr ::sus::option::Option<NonNull<T>> with_ptr(U t) noexcept
  • public template <class U, size_t N>static inline constexpr ::sus::option::Option<NonNull<T>> with_ptr(U (&)[N] t)
  • public template <class U>static inline constexpr NonNull<T> with_ptr_unchecked(::sus::marker::UnsafeFnMarker, U _Nonnull t) noexcept
  • public template <class U, size_t N>static inline constexpr NonNull<T> with_ptr_unchecked(U (&)[N] t)

Methods

constexpr NonNull<T>(T& t) noexcept

Description

Constructs a `NonNull <T >` from a reference to `T`.

Declared at: sus/ptr/nonnull.h:49

Parameters

T& t

inline constexpr T& as_mut() noexcept

Description

Returns a mutable reference to the pointee. This method is only callable when the pointer is not const.

Declared at: sus/ptr/nonnull.h:113

inline constexpr T* as_mut_ptr() noexcept

Description

Returns a mutable pointer to the pointee. This method is only callable when the pointer is not const.

Declared at: sus/ptr/nonnull.h:125

inline constexpr const T* as_ptr() const noexcept

Description

Returns a const pointer to the pointee.

Declared at: sus/ptr/nonnull.h:120

inline constexpr const T& as_ref() const noexcept

Description

Returns a const reference to the pointee.

Declared at: sus/ptr/nonnull.h:108

template <class U>
NonNull<U> cast() const noexcept

Description

Cast the pointer of type `T` in `NonNull <T >` to a pointer of type `U` and return a `NonNull <U >`. This requires that `T*` is a subclass of `U*`. To perform a downcast, like static_cast <U *> allows, use `downcast()`.

Declared at: sus/ptr/nonnull.h:138

Templates

U

template <class U>
NonNull<U> downcast(
    ::sus::marker::UnsafeFnMarker) const noexcept

Description

Cast the pointer of type `T` in `NonNull <T >` to a pointer of type `U` and return a `NonNull <U >`. # Safety The pointee must be a `U*` or this results in Undefined Behaviour.

Declared at: sus/ptr/nonnull.h:149

Templates

U

Parameters

::sus::marker::UnsafeFnMarker

static inline constexpr NonNull<T> from(
    T& t) noexcept

Description

Satisfies the [`sus::construct::From <NonNull <T >, T & >`]($sus::construct::From) concept.

Declared at: sus/ptr/nonnull.h:91

Parameters

T& t

template <class U, size_t N>
static inline constexpr NonNull<T> from(
    U (&)[N] t)

Declared at: sus/ptr/nonnull.h:94

Templates

U
size_t N

Parameters

U (&)[N] t

template <class U>
static inline constexpr ::sus::option::Option<
    NonNull<T>>
with_ptr(U t) noexcept

Description

Constructs a `NonNull <T >` from a pointer to `T`. Does not implicitly convert from an array. The caller must explicitly convert it to a pointer to throw away the length of the array. # Panics The method will panic if the pointer `t` is null.

Declared at: sus/ptr/nonnull.h:59

Templates

U

Parameters

U t

template <class U, size_t N>
static inline constexpr ::sus::option::Option<
    NonNull<T>>
with_ptr(U (&)[N] t)

Declared at: sus/ptr/nonnull.h:68

Templates

U
size_t N

Parameters

U (&)[N] t

template <class U>
static inline constexpr NonNull<T>
    with_ptr_unchecked(
        ::sus::marker::UnsafeFnMarker,
        U _Nonnull t) noexcept

Description

Constructs a `NonNull <T >` from a pointer to `T`. Does not implicitly convert from an array. The caller must explicitly convert it to a pointer to throw away the length of the array. # Safety This method must not be called with a null pointer, or Undefined Behaviour results.

Declared at: sus/ptr/nonnull.h:81

Templates

U

Parameters

::sus::marker::UnsafeFnMarker
U _Nonnull t

template <class U, size_t N>
static inline constexpr NonNull<T>
with_ptr_unchecked(U (&)[N] t)

Declared at: sus/ptr/nonnull.h:87

Templates

U
size_t N

Parameters

U (&)[N] t