Skip to content

Class endstone::NotNull

template <class T>

ClassList > endstone > NotNull

A wrapper around a std::shared_ptr that documents that it is never null. More...

  • #include <endstone/util/pointers.h>

Public Types

Type Name
typedef T element_type
typedef std::shared_ptr< T > pointer_type

Public Functions

Type Name
NotNull () = delete
NotNull (std::shared_ptr< T > ptr)
NotNull (const NotNull & other) = default
NotNull (std::shared_ptr< U > ptr)
Covariant conversion from a shared_ptr of a convertible (e.g.
NotNull (const NotNull< U > & other)
Covariant conversion from a NotNull of a convertible (e.g.
NotNull (const Nullable< T > & other)
Narrowing conversion from a Nullable .
NotNull (std::nullptr_t) = delete
Nullable< U > as () const
Attempts to narrow the pointee to the given type U, keeping the shared ownership.
NotNull< U > cast () const
const pointer_type & get () noexcept const
bool is () const
Checks if the pointee is an instance of the given type U (or a subclass of U).
T & operator* () noexcept const
NotNull & operator++ () = delete
NotNull operator++ (int) = delete
NotNull & operator+= (std::ptrdiff_t) = delete
NotNull & operator-- () = delete
NotNull operator-- (int) = delete
NotNull & operator-= (std::ptrdiff_t) = delete
T * operator-> () noexcept const
NotNull & operator= (const NotNull & other) = default
NotNull & operator= (std::nullptr_t) = delete
void operator[] (std::ptrdiff_t) const
void swap (NotNull & other) noexcept

Detailed Description

This carries the same weight as Java's @ NotNull: it states the contract and costs nothing at run time. Passing nullptr is a compile error, as are the pointer-mutating operators, but a null shared_ptr handed over at run time is not diagnosed. Validate at the boundary where the pointer enters the API, not here.

Public Types Documentation

typedef element_type

using endstone::NotNull< T >::element_type =  T;

typedef pointer_type

using endstone::NotNull< T >::pointer_type =  std::shared_ptr<T>;

Public Functions Documentation

function NotNull [1/7]

endstone::NotNull::NotNull () = delete

function NotNull [2/7]

inline endstone::NotNull::NotNull (
    std::shared_ptr< T > ptr
) 

function NotNull [3/7]

endstone::NotNull::NotNull (
    const  NotNull & other
) = default

function NotNull [4/7]

Covariant conversion from a shared_ptr of a convertible (e.g.

template<class  U>
inline endstone::NotNull::NotNull (
    std::shared_ptr< U > ptr
) 

derived) type.


function NotNull [5/7]

Covariant conversion from a NotNull of a convertible (e.g.

template<class  U>
inline endstone::NotNull::NotNull (
    const  NotNull < U > & other
) 

derived) type.


function NotNull [6/7]

Narrowing conversion from a Nullable .

endstone::NotNull::NotNull (
    const  Nullable < T > & other
) 


function NotNull [7/7]

endstone::NotNull::NotNull (
    std::nullptr_t
) = delete

function as

Attempts to narrow the pointee to the given type U, keeping the shared ownership.

template<class  U>
inline Nullable < U > endstone::NotNull::as () const

Returns a null Nullable if the pointee is not an instance of U (or a subclass of U).

Template parameters:

  • U Target type to narrow to (must derive from Object)

Returns:

A Nullable holding this as U, or a null Nullable if the narrowing is invalid


function cast

template<class  U>
inline NotNull < U > endstone::NotNull::cast () const

function get

inline const pointer_type & endstone::NotNull::get () noexcept const

function is

Checks if the pointee is an instance of the given type U (or a subclass of U).

template<class  U>
inline bool endstone::NotNull::is () const

Template parameters:

  • U Type to check against (must derive from Object)

Returns:

true if the pointee is an instance of U


function operator*

inline T & endstone::NotNull::operator* () noexcept const

function operator++

NotNull & endstone::NotNull::operator++ () = delete

function operator++

NotNull endstone::NotNull::operator++ (
    int
) = delete

function operator+=

NotNull & endstone::NotNull::operator+= (
    std::ptrdiff_t
) = delete

function operator--

NotNull & endstone::NotNull::operator-- () = delete

function operator--

NotNull endstone::NotNull::operator-- (
    int
) = delete

function operator-=

NotNull & endstone::NotNull::operator-= (
    std::ptrdiff_t
) = delete

function operator->

inline T * endstone::NotNull::operator-> () noexcept const

function operator=

NotNull & endstone::NotNull::operator= (
    const  NotNull & other
) = default

function operator=

NotNull & endstone::NotNull::operator= (
    std::nullptr_t
) = delete

function operator[]

void endstone::NotNull::operator[] (
    std::ptrdiff_t
) const

function swap

inline void endstone::NotNull::swap (
    NotNull & other
) noexcept


The documentation for this class was generated from the following file include/endstone/util/pointers.h