Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
arene::base::non_null< P > Class Template Reference

A pointer type which is never nullptr. More...

Inheritance diagram for arene::base::non_null< P >:
Inheritance graph

Public Types

using element_type = typename std::pointer_traits<held_pointer>::element_type
 The type of the element pointed to.
 
using held_pointer = P
 The pointer type being wrapped by the non_null .
 

Public Member Functions

constexpr non_null ()=delete
 non_null cannot be default constructed
 
constexpr non_null (non_null &&)=default
 Default move constructor.
 
constexpr non_null (non_null const &)=default
 Default copy constructor.
 
template<typename U = held_pointer, constraints< std::enable_if_t< std::is_constructible< held_pointer, U && >::value > > = nullptr>
constexpr non_null (non_null< U > &&move_from) noexcept(std::is_nothrow_constructible< held_pointer, U && >::value)
 Move constructor from non_null.
 
template<typename U = held_pointer, constraints< std::enable_if_t< std::is_constructible< held_pointer, U const & >::value > > = nullptr>
constexpr non_null (non_null< U > const &copy_from) noexcept(std::is_nothrow_constructible< held_pointer, U const & >::value)
 Copy constructor from non_null.
 
constexpr non_null (std::nullptr_t)=delete
 non_null cannot be constructed from a literal nullptr .
 
template<typename U, constraints< std::enable_if_t<!is_non_null_v< U >, std::enable_if_t< std::is_constructible< held_pointer, U >::value > > > = nullptr>
constexpr non_null (U &&ptr_value) noexcept(std::is_nothrow_constructible< held_pointer, U >::value)
 Construction from a pointer type.
 
 ~non_null ()=default
 Default destructor.
 
ARENE_NODISCARD constexpr auto operator! () const noexcept -> bool
 Boolean negation operator, equivalent to a == comparison to nullptr.
 
template<typename U = element_type, typename = std::enable_if_t<!std::is_same<std::remove_cv_t<U>, void>::value>>
ARENE_NODISCARD constexpr auto operator* () const noexcept ->
 Dereference operator.
 
template<typename U = element_type, typename = std::enable_if_t<!std::is_same<std::remove_cv_t<U>, void>::value>>
ARENE_NODISCARD constexpr auto operator-> () const noexcept -> pointer
 Arrow operator.
 
constexpr auto operator= (non_null &&) -> non_null &=default
 Default move assignment.
 
constexpr auto operator= (non_null const &) -> non_null &=default
 Default copy assignment.
 
template<typename U = held_pointer, constraints< std::enable_if_t< std::is_assignable< held_pointer &, U && >::value > > = nullptr>
constexpr auto operator= (non_null< U > &&move_from) noexcept(std::is_nothrow_assignable< held_pointer &, U && >::value) -> non_null &
 Move assignment from non_null.
 
template<typename U = held_pointer, constraints< std::enable_if_t< std::is_assignable< held_pointer &, U const & >::value > > = nullptr>
constexpr auto operator= (non_null< U > const &copy_from) noexcept(std::is_nothrow_assignable< held_pointer &, U const & >::value) -> non_null &
 Copy assignment from non_null.
 
template<typename U = held_pointer, constraints< std::enable_if_t<!is_non_null_v< U > >, std::enable_if_t< std::is_assignable< held_pointer &, U >::value > > = nullptr>
constexpr auto operator= (U &&new_ptr) noexcept(std::is_nothrow_assignable< held_pointer &, U >::value) -> non_null &
 Assignment from a pointer type.
 
constexpr void reset (std::nullptr_t) noexcept=delete
 Resetting to a nullptr literal is not supported.
 
template<typename U = held_pointer, constraints< std::enable_if_t< arene::base::pointer::detail::has_reset< held_pointer &, U > > > = nullptr>
constexpr void reset (U &&reset_to) noexcept(noexcept(std::declval< held_pointer >().reset(std::declval< U >())))
 Re-assigns the non_null to a new held pointer.
 
template<typename U = held_pointer, constraints< std::enable_if_t<!arene::base::pointer::detail::has_reset< held_pointer &, U > >, std::enable_if_t< std::is_assignable< held_pointer &, U >::value > > = nullptr>
constexpr void reset (U &&reset_to) noexcept(std::is_nothrow_assignable< held_pointer &, U >::value)
 Re-assigns the non_null to a new held pointer.
 
template<typename U = P, constraints< std::enable_if_t< is_swappable_v< P > > > = nullptr>
constexpr void swap (non_null &swap_with) noexcept(is_nothrow_swappable_v< P >)
 Swaps this with another non_null .
 
template<typename U = held_pointer, constraints< std::enable_if_t< std::is_pointer< U >::value > > = nullptr>
ARENE_NODISCARD constexpr auto get () const noexcept -> held_pointer
 Gets a pointer to the pointed-to element.
 
template<typename U = held_pointer, constraints< std::enable_if_t<!std::is_pointer< U >::value > > = nullptr>
ARENE_NODISCARD constexpr auto get () const noexcept ->
 Gets a pointer to the pointed-to element.
 
ARENE_NODISCARD constexpr auto unwrap () const &noexcept -> held_pointer const &
 Gets the held pointer backing the non_null.
 
template<typename U = held_pointer, constraints< std::enable_if_t<!std::is_pointer< U >::value > > = nullptr>
ARENE_NODISCARD constexpr auto unwrap () &&noexcept -> held_pointer &&
 Gets the held pointer backing the non_null.
 
template<typename U = held_pointer, constraints< std::enable_if_t<!std::is_pointer< U >::value > > = nullptr>
ARENE_NODISCARD constexpr operator bool () const noexcept
 Conversion to bool , equivalent to a != comparison to nullptr.
 
template<typename U = held_pointer, constraints< std::enable_if_t< std::is_pointer< U >::value > > = nullptr>
ARENE_NODISCARD constexpr operator bool () const noexcept
 Conversion to bool , equivalent to a != comparison to nullptr.
 
ARENE_NODISCARD constexpr operator held_pointer const & () const &noexcept
 Implicit conversion operator to the underlying pointer.
 
template<typename U = held_pointer, constraints< std::enable_if_t<!std::is_pointer< U >::value > > = nullptr>
ARENE_NODISCARD constexpr operator held_pointer && () &&noexcept
 Implicit conversion operator to the underlying pointer.
 
template<typename U, constraints< std::enable_if_t<!is_non_null_v< U > >, std::enable_if_t< std::is_constructible< U, held_pointer const & >::value > > = nullptr>
ARENE_NODISCARD constexpr operator U () const &noexcept(std::is_nothrow_constructible< U, held_pointer const & >::value)
 Explicit conversion operator to U.
 
template<typename U, constraints< std::enable_if_t<!is_non_null_v< U > >, std::enable_if_t<!std::is_pointer< U >::value >, std::enable_if_t< std::is_constructible< U, held_pointer && >::value > > = nullptr>
ARENE_NODISCARD constexpr operator U () &&noexcept(std::is_nothrow_constructible< U, held_pointer && >::value)
 Explicit conversion operator to U.
 
template<typename I>
constexpr auto operator[] (I)=delete
 Pointer arithmetic is explicitly deleted.
 
template<typename I>
constexpr auto operator[] (I) const =delete
 Pointer arithmetic is explicitly deleted.
 
template<typename I>
constexpr auto operator+ (I const &) const -> non_null=delete
 Pointer arithmetic is explicitly deleted.
 
template<typename I>
constexpr auto operator- (I const &) const -> non_null=delete
 Pointer arithmetic is explicitly deleted.
 
constexpr auto operator++ () -> non_null &=delete
 Pointer arithmetic is explicitly deleted.
 
constexpr auto operator++ (int) -> non_null &=delete
 Pointer arithmetic is explicitly deleted.
 
constexpr auto operator-- () -> non_null &=delete
 Pointer arithmetic is explicitly deleted.
 
constexpr auto operator-- (int) -> non_null &=delete
 Pointer arithmetic is explicitly deleted.
 

Static Public Member Functions

template<typename Dummy = held_pointer, constraints< std::enable_if_t< std::is_pointer< Dummy >::value > > = nullptr>
static ARENE_NODISCARD constexpr auto three_way_compare (non_null const &, std::nullptr_t const) noexcept -> strong_ordering
 Three-way comparison of non_null against a null pointer.
 
template<typename OtherType, constraints< std::enable_if_t< compare_three_way_supported_v< held_pointer const &, OtherType const & > > > = nullptr>
static ARENE_NODISCARD constexpr auto three_way_compare (non_null const &lhs, non_null< OtherType > const &rhs) noexcept -> strong_ordering
 Three-way comparison between two non_null instances. The result is equivalent to comparing the held pointers.
 
template<typename OtherType, constraints< std::enable_if_t< compare_three_way_supported_v< held_pointer const &, OtherType const & > >, std::enable_if_t<!is_non_null_v< OtherType > > > = nullptr>
static ARENE_NODISCARD constexpr auto three_way_compare (non_null const &lhs, OtherType const &rhs) noexcept -> strong_ordering
 Three-way comparison of non_null against another value. The result is equivalent to comparing the held pointer against that other value.
 
template<typename Dummy = held_pointer, constraints< std::enable_if_t<!std::is_pointer< Dummy >::value > > = nullptr>
static ARENE_NODISCARD constexpr auto three_way_compare (non_null const &lhs, std::nullptr_t const) noexcept -> strong_ordering
 Three-way comparison of non_null against a null pointer.
 

Public Attributes

using pointer
 The type of a raw pointer to the element pointed to by the non_null .
 

Friends

template<typename OtherType, constraints< std::enable_if_t< is_equality_comparable_v< held_pointer const &, OtherType const & > > > = nullptr>
ARENE_NODISCARD friend constexpr auto operator== (non_null const &lhs, non_null< OtherType > const &rhs) noexcept -> bool
 Equality comparison between two non_null instances. The result is equivalent to comparing the held pointers.
 
ARENE_NODISCARD friend constexpr auto operator== (non_null const &lhs, std::nullptr_t const rhs) noexcept -> bool
 Equality comparison of non_null against a null pointer.
 
template<typename NonNullType, typename OtherType, constraints< std::enable_if_t< std::is_same< NonNullType, non_null >::value >, std::enable_if_t<!is_non_null_v< OtherType > >, std::enable_if_t< is_equality_comparable_v< held_pointer const &, OtherType const & > > > = nullptr>
ARENE_NODISCARD friend constexpr auto operator== (NonNullType const &lhs, OtherType const &rhs) noexcept -> bool
 Equality comparison of non_null against another value. The result is equivalent to comparing the held pointer against that other value.
 
template<typename U = P, constraints< std::enable_if_t< is_swappable_v< P > > > = nullptr>
constexpr void swap (non_null &lhs, non_null &rhs) noexcept(noexcept(lhs.swap(rhs)))
 Swaps two non_null .
 

Detailed Description

template<typename P>
class arene::base::non_null< P >

A pointer type which is never nullptr.

Template Parameters
PThe type of the pointer to wrap.

A wrapper type around a "pointer type" which maintains the invariant that the pointer never be nullptr . It is considered a "malformed program" to attempt to construct a non_null with a pointer which is nullptr , and thus an ARENE_PRECONDITION violation.

non_null

models the wrapped pointer type. This means the following properties are true:

  • It is copyable if the wrapped pointer is copyable.
  • It is movable if the wrapped pointer is movable.
  • It is implicitly convertible to (a reference to) the wrapped pointer.
  • It is 6-way comparable with the same semantics as the wrapped pointer.
  • The dereference/arrow operators are equivalent to dereferencing the wrapped pointer.
  • Calling get() is equivalent to calling get() on the wrapped pointer if the wrapped pointer is a smart pointer. See non_null<P>::get() for details.
  • Calling reset() is equivalent to calling reset() on the wrapped pointer, if the wrapped pointer is a smart pointer. See non_null<P>::reset() for details.

To maintain the invariant that the pointer is never nullptr , it is not possible to obtain a non-const lvalue reference to the wrapped pointer. If P is not a raw pointer, it is possible to obtain an rvalue reference to the wrapped pointer via unwrap()&& or by casting from an rvalue-qualified non_null .

Warning
In order to be useful in real programs, a moved-from non_null which contains anything other than a raw pointer may become nullptr . Thus the only valid operations which may be performed on a moved-from non_null is to either assign/reset it to a new value, or let it be destroyed.

Member Typedef Documentation

◆ element_type

template<typename P>
using arene::base::non_null< P >::element_type = typename std::pointer_traits<held_pointer>::element_type

The type of the element pointed to.

◆ held_pointer

template<typename P>
using arene::base::non_null< P >::held_pointer = P

The pointer type being wrapped by the non_null .

Constructor & Destructor Documentation

◆ non_null() [1/7]

template<typename P>
arene::base::non_null< P >::non_null ( )
constexprdelete

non_null cannot be default constructed

◆ non_null() [2/7]

template<typename P>
arene::base::non_null< P >::non_null ( std::nullptr_t )
explicitconstexprdelete

non_null cannot be constructed from a literal nullptr .

◆ non_null() [3/7]

template<typename P>
arene::base::non_null< P >::non_null ( non_null< P > const & )
constexprdefault

Default copy constructor.

◆ non_null() [4/7]

template<typename P>
arene::base::non_null< P >::non_null ( non_null< P > && )
constexprdefault

Default move constructor.

◆ ~non_null()

template<typename P>
arene::base::non_null< P >::~non_null ( )
default

Default destructor.

◆ non_null() [5/7]

template<typename P>
template<typename U, constraints< std::enable_if_t<!is_non_null_v< U >, std::enable_if_t< std::is_constructible< held_pointer, U >::value > > > = nullptr>
arene::base::non_null< P >::non_null ( U && ptr_value)
inlineexplicitconstexprnoexcept

Construction from a pointer type.

Template Parameters
UThe type of the pointer to construct from. Must be convertible to held_pointer
Parameters
ptr_valueThe pointer to construct from.
Precondition
ptr_value must not be nullptr , or else ARENE_PRECONDITION violation.
Postcondition
get() will return a pointer to the element pointed to by ptr_value .

◆ non_null() [6/7]

template<typename P>
template<typename U = held_pointer, constraints< std::enable_if_t< std::is_constructible< held_pointer, U const & >::value > > = nullptr>
arene::base::non_null< P >::non_null ( non_null< U > const & copy_from)
inlineconstexprnoexcept

Copy constructor from non_null.

Template Parameters
UType of the held pointer of the non_null to copy
Parameters
copy_fromThe non_null to copy

◆ non_null() [7/7]

template<typename P>
template<typename U = held_pointer, constraints< std::enable_if_t< std::is_constructible< held_pointer, U && >::value > > = nullptr>
arene::base::non_null< P >::non_null ( non_null< U > && move_from)
inlineconstexprnoexcept

Move constructor from non_null.

Template Parameters
UType of the held pointer of the non_null to move
Parameters
move_fromThe non_null to move

Member Function Documentation

◆ get() [1/2]

template<typename P>
template<typename U = held_pointer, constraints< std::enable_if_t<!std::is_pointer< U >::value > > = nullptr>
ARENE_NODISCARD constexpr auto arene::base::non_null< P >::get ( ) const ->
inlineconstexprnoexcept

Gets a pointer to the pointed-to element.

Returns
pointer A pointer to the pointed-to element. The type is pointer .
Invariant
The returned pointer will never be equal to nullptr .

Behavior is as if non_null

models P . This means that:

◆ get() [2/2]

template<typename P>
template<typename U = held_pointer, constraints< std::enable_if_t< std::is_pointer< U >::value > > = nullptr>
ARENE_NODISCARD constexpr auto arene::base::non_null< P >::get ( ) const -> held_pointer
inlineconstexprnoexcept

Gets a pointer to the pointed-to element.

Returns
pointer A pointer to the pointed-to element. The type is pointer .
Invariant
The returned pointer will never be equal to nullptr .

Behavior is as if non_null

models P . This means that:

  • If P is a raw pointer, then returns the pointer.
  • If P is a "smart" pointer, then forwards the return from calling get() on the smart pointer. Examples:
    decltype(non_null<int*>.get()) == int*;
    decltype(non_null<std::unique_ptr<int*>>.get()) == int*;

◆ operator bool() [1/2]

template<typename P>
template<typename U = held_pointer, constraints< std::enable_if_t<!std::is_pointer< U >::value > > = nullptr>
ARENE_NODISCARD constexpr arene::base::non_null< P >::operator bool ( ) const
inlineexplicitconstexprnoexcept

Conversion to bool , equivalent to a != comparison to nullptr.

Returns
true non_null can never contain nullptr , so the return is always true .

◆ operator bool() [2/2]

template<typename P>
template<typename U = held_pointer, constraints< std::enable_if_t< std::is_pointer< U >::value > > = nullptr>
ARENE_NODISCARD constexpr arene::base::non_null< P >::operator bool ( ) const
inlineexplicitconstexprnoexcept

Conversion to bool , equivalent to a != comparison to nullptr.

Returns
true non_null can never contain nullptr , so the return is always true .

◆ operator held_pointer &&()

template<typename P>
template<typename U = held_pointer, constraints< std::enable_if_t<!std::is_pointer< U >::value > > = nullptr>
ARENE_NODISCARD constexpr arene::base::non_null< P >::operator held_pointer && ( ) &&
inlineconstexprnoexcept

Implicit conversion operator to the underlying pointer.

Returns
The underlying pointer. If held_pointer is a raw pointer or sufficiently trivial type, this will be a by-value return. Otherwise, it will be a reference.

◆ operator held_pointer const &()

template<typename P>
ARENE_NODISCARD constexpr arene::base::non_null< P >::operator held_pointer const & ( ) const &
inlineconstexprnoexcept

Implicit conversion operator to the underlying pointer.

Returns
The underlying pointer. If held_pointer is a raw pointer or sufficiently trivial type, this will be a by-value return. Otherwise, it will be a reference.

◆ operator U() [1/2]

template<typename P>
template<typename U, constraints< std::enable_if_t<!is_non_null_v< U > >, std::enable_if_t<!std::is_pointer< U >::value >, std::enable_if_t< std::is_constructible< U, held_pointer && >::value > > = nullptr>
ARENE_NODISCARD constexpr arene::base::non_null< P >::operator U ( ) &&
inlineexplicitconstexprnoexcept

Explicit conversion operator to U.

Template Parameters
UThe type to convert the non_null to. held_pointer must be convertible to U .
Returns
U An instance of the converted-to type produced by applying static_cast<U>() to the held pointer.

◆ operator U() [2/2]

template<typename P>
template<typename U, constraints< std::enable_if_t<!is_non_null_v< U > >, std::enable_if_t< std::is_constructible< U, held_pointer const & >::value > > = nullptr>
ARENE_NODISCARD constexpr arene::base::non_null< P >::operator U ( ) const &
inlineexplicitconstexprnoexcept

Explicit conversion operator to U.

Template Parameters
UThe type to convert the non_null to. held_pointer must be convertible to U .
Returns
U An instance of the converted-to type produced by applying static_cast<U>() to the held pointer.

◆ operator!()

template<typename P>
ARENE_NODISCARD constexpr auto arene::base::non_null< P >::operator! ( ) const -> bool
inlineconstexprnoexcept

Boolean negation operator, equivalent to a == comparison to nullptr.

Returns
false non_null can never contain nullptr , so the return is always false .

◆ operator*()

template<typename P>
template<typename U = element_type, typename = std::enable_if_t<!std::is_same<std::remove_cv_t<U>, void>::value>>
ARENE_NODISCARD constexpr auto arene::base::non_null< P >::operator* ( ) const ->
inlineconstexprnoexcept

Dereference operator.

Returns
element_type& A reference to the pointed-to element.
Invariant
The returned pointer will never be equal to nullptr .
Note
Only exists if held_pointer is not void* .

◆ operator+()

template<typename P>
template<typename I>
auto arene::base::non_null< P >::operator+ ( I const & ) const -> non_null=delete
constexprdelete

Pointer arithmetic is explicitly deleted.

◆ operator++() [1/2]

template<typename P>
auto arene::base::non_null< P >::operator++ ( ) -> non_null &=delete
constexprdelete

Pointer arithmetic is explicitly deleted.

◆ operator++() [2/2]

template<typename P>
auto arene::base::non_null< P >::operator++ ( int ) -> non_null &=delete
constexprdelete

Pointer arithmetic is explicitly deleted.

◆ operator-()

template<typename P>
template<typename I>
auto arene::base::non_null< P >::operator- ( I const & ) const -> non_null=delete
constexprdelete

Pointer arithmetic is explicitly deleted.

◆ operator--() [1/2]

template<typename P>
auto arene::base::non_null< P >::operator-- ( ) -> non_null &=delete
constexprdelete

Pointer arithmetic is explicitly deleted.

◆ operator--() [2/2]

template<typename P>
auto arene::base::non_null< P >::operator-- ( int ) -> non_null &=delete
constexprdelete

Pointer arithmetic is explicitly deleted.

◆ operator->()

template<typename P>
template<typename U = element_type, typename = std::enable_if_t<!std::is_same<std::remove_cv_t<U>, void>::value>>
ARENE_NODISCARD constexpr auto arene::base::non_null< P >::operator-> ( ) const -> pointer
inlineconstexprnoexcept

Arrow operator.

Returns
pointer A pointer to the pointed-to element
Invariant
The returned pointer will never be equal to nullptr .
Note
Only exists if held_pointer is not void* .

◆ operator=() [1/5]

template<typename P>
auto arene::base::non_null< P >::operator= ( non_null< P > && ) -> non_null &=default
constexprdefault

Default move assignment.

◆ operator=() [2/5]

template<typename P>
auto arene::base::non_null< P >::operator= ( non_null< P > const & ) -> non_null &=default
constexprdefault

Default copy assignment.

◆ operator=() [3/5]

template<typename P>
template<typename U = held_pointer, constraints< std::enable_if_t< std::is_assignable< held_pointer &, U && >::value > > = nullptr>
auto arene::base::non_null< P >::operator= ( non_null< U > && move_from) -> non_null&
inlineconstexprnoexcept

Move assignment from non_null.

Template Parameters
UType of the held pointer of the non_null to move. Must be assignable to held_pointer .
Parameters
move_fromThe non_null to move

◆ operator=() [4/5]

template<typename P>
template<typename U = held_pointer, constraints< std::enable_if_t< std::is_assignable< held_pointer &, U const & >::value > > = nullptr>
auto arene::base::non_null< P >::operator= ( non_null< U > const & copy_from) -> non_null&
inlineconstexprnoexcept

Copy assignment from non_null.

Template Parameters
UType of the held pointer of the non_null to copy. Must be assignable to held_pointer .
Parameters
copy_fromThe non_null to copy

◆ operator=() [5/5]

template<typename P>
template<typename U = held_pointer, constraints< std::enable_if_t<!is_non_null_v< U > >, std::enable_if_t< std::is_assignable< held_pointer &, U >::value > > = nullptr>
auto arene::base::non_null< P >::operator= ( U && new_ptr) -> non_null&
inlineconstexprnoexcept

Assignment from a pointer type.

Template Parameters
UThe type of the pointer to assign from. Must be assignable to held_pointer
Parameters
new_ptrThe pointer to assign from.
Precondition
new_ptr must not be nullptr , or else ARENE_PRECONDITION violation.

◆ operator[]() [1/2]

template<typename P>
template<typename I>
auto arene::base::non_null< P >::operator[] ( I ) const
constexprdelete

Pointer arithmetic is explicitly deleted.

◆ operator[]() [2/2]

template<typename P>
template<typename I>
auto arene::base::non_null< P >::operator[] ( I )
constexprdelete

Pointer arithmetic is explicitly deleted.

◆ reset() [1/3]

template<typename P>
void arene::base::non_null< P >::reset ( std::nullptr_t )
constexprdeletenoexcept

Resetting to a nullptr literal is not supported.

◆ reset() [2/3]

template<typename P>
template<typename U = held_pointer, constraints< std::enable_if_t< arene::base::pointer::detail::has_reset< held_pointer &, U > > > = nullptr>
void arene::base::non_null< P >::reset ( U && reset_to)
inlineconstexprnoexcept

Re-assigns the non_null to a new held pointer.

The reset is performed using held_pointer::reset() .

Template Parameters
UThe type of pointer to rest with. Must be valid to call held_pointer::rest(U) .
Parameters
reset_toThe pointer to reset the non_null to.
Precondition
ptr must not be nullptr , or else ARENE_PRECONDITION violation.
Postcondition
The state of the object is as if it had been constructed by ptr .
Note
does not participate in overload resolution if held_pointer::reset(U) is not well formed.

◆ reset() [3/3]

template<typename P>
template<typename U = held_pointer, constraints< std::enable_if_t<!arene::base::pointer::detail::has_reset< held_pointer &, U > >, std::enable_if_t< std::is_assignable< held_pointer &, U >::value > > = nullptr>
void arene::base::non_null< P >::reset ( U && reset_to)
inlineconstexprnoexcept

Re-assigns the non_null to a new held pointer.

The reset is performed by assignment to the held pointer.

Template Parameters
UThe type of pointer to rest with. Must be assignable to held_pointer
Parameters
reset_toThe pointer to reset the non_null to.
Precondition
ptr must not be nullptr , or else ARENE_PRECONDITION violation.
Postcondition
The state of the object is as if it had been constructed by ptr .
Note
does not participate in overload resolution if held_pointer::reset(U) is well formed.

◆ swap()

template<typename P>
template<typename U = P, constraints< std::enable_if_t< is_swappable_v< P > > > = nullptr>
void arene::base::non_null< P >::swap ( non_null< P > & swap_with)
inlineconstexprnoexcept

Swaps this with another non_null .

Template Parameters
UMust satisfy arene::base::is_swappable_v
Parameters
swap_withThe non_null to swap with.
Postcondition
this is equal to the original swap_with, and swap_with is equal to the original this .

◆ three_way_compare() [1/4]

template<typename P>
template<typename Dummy = held_pointer, constraints< std::enable_if_t< std::is_pointer< Dummy >::value > > = nullptr>
static ARENE_NODISCARD constexpr auto arene::base::non_null< P >::three_way_compare ( non_null< P > const & ,
std::nullptr_t const  ) -> strong_ordering
inlinestaticconstexprnoexcept

Three-way comparison of non_null against a null pointer.

Template Parameters
DummyDummy template parameter that is the same as held_pointer to enable SFINAE
Returns
The result of this check is always strong_ordering::greater

◆ three_way_compare() [2/4]

template<typename P>
template<typename OtherType, constraints< std::enable_if_t< compare_three_way_supported_v< held_pointer const &, OtherType const & > > > = nullptr>
static ARENE_NODISCARD constexpr auto arene::base::non_null< P >::three_way_compare ( non_null< P > const & lhs,
non_null< OtherType > const & rhs ) -> strong_ordering
inlinestaticconstexprnoexcept

Three-way comparison between two non_null instances. The result is equivalent to comparing the held pointers.

Template Parameters
OtherTypeThe type held in the other non_null instance being compared to. held_pointer must be three-way-comparable to OtherType .
Parameters
lhsThe first value being compared
rhsThe second value being compared
Returns
The result of the three-way comparison of the held pointer of lhs to the held pointer of rhs

◆ three_way_compare() [3/4]

template<typename P>
template<typename OtherType, constraints< std::enable_if_t< compare_three_way_supported_v< held_pointer const &, OtherType const & > >, std::enable_if_t<!is_non_null_v< OtherType > > > = nullptr>
static ARENE_NODISCARD constexpr auto arene::base::non_null< P >::three_way_compare ( non_null< P > const & lhs,
OtherType const & rhs ) -> strong_ordering
inlinestaticconstexprnoexcept

Three-way comparison of non_null against another value. The result is equivalent to comparing the held pointer against that other value.

Template Parameters
OtherTypeThe type to compare the non_null to. It must not be a instantiation of non_null. held_pointer must be comparable to OtherType .
Parameters
lhsThe first value being compared
rhsThe second value being compared
Returns
The result of the three-way comparison of the held pointer of lhs to rhs

◆ three_way_compare() [4/4]

template<typename P>
template<typename Dummy = held_pointer, constraints< std::enable_if_t<!std::is_pointer< Dummy >::value > > = nullptr>
static ARENE_NODISCARD constexpr auto arene::base::non_null< P >::three_way_compare ( non_null< P > const & lhs,
std::nullptr_t const  ) -> strong_ordering
inlinestaticconstexprnoexcept

Three-way comparison of non_null against a null pointer.

Template Parameters
DummyDummy template parameter that is the same as held_pointer to enable SFINAE
Parameters
lhsThe non_null value being compared
Returns
The result of this check is always strong_ordering::greater unless the non_null instance has been moved from, and wraps a movable smart pointer like std::unique_ptr

◆ unwrap() [1/2]

template<typename P>
template<typename U = held_pointer, constraints< std::enable_if_t<!std::is_pointer< U >::value > > = nullptr>
ARENE_NODISCARD constexpr auto arene::base::non_null< P >::unwrap ( ) && -> held_pointer&&
inlineconstexprnoexcept

Gets the held pointer backing the non_null.

Returns
A reference to the underlying pointer.

◆ unwrap() [2/2]

template<typename P>
ARENE_NODISCARD constexpr auto arene::base::non_null< P >::unwrap ( ) const & -> held_pointer const&
inlineconstexprnoexcept

Gets the held pointer backing the non_null.

Returns
A reference to the underlying pointer.

Friends And Related Symbol Documentation

◆ operator== [1/3]

template<typename P>
template<typename OtherType, constraints< std::enable_if_t< is_equality_comparable_v< held_pointer const &, OtherType const & > > > = nullptr>
ARENE_NODISCARD friend constexpr auto operator== ( non_null< P > const & lhs,
non_null< OtherType > const & rhs ) -> bool
friend

Equality comparison between two non_null instances. The result is equivalent to comparing the held pointers.

Template Parameters
OtherTypeThe type held in the other non_null instance being compared to. held_pointer must be comparable to OtherType .
Parameters
lhsThe first value being compared
rhsThe second value being compared
Returns
The result of the comparison of the held pointer of lhs to the held pointer of rhs

◆ operator== [2/3]

template<typename P>
ARENE_NODISCARD friend constexpr auto operator== ( non_null< P > const & lhs,
std::nullptr_t const rhs ) -> bool
friend

Equality comparison of non_null against a null pointer.

Parameters
lhsThe first value being compared
rhsThe second value being compared
Returns
The result of this check is always false unless the non_null instance has been moved from, and wraps a movable smart pointer like std::unique_ptr

◆ operator== [3/3]

template<typename P>
template<typename NonNullType, typename OtherType, constraints< std::enable_if_t< std::is_same< NonNullType, non_null >::value >, std::enable_if_t<!is_non_null_v< OtherType > >, std::enable_if_t< is_equality_comparable_v< held_pointer const &, OtherType const & > > > = nullptr>
ARENE_NODISCARD friend constexpr auto operator== ( NonNullType const & lhs,
OtherType const & rhs ) -> bool
friend

Equality comparison of non_null against another value. The result is equivalent to comparing the held pointer against that other value.

Template Parameters
NonNullTypeMust be non_null This is a constrained template parameter to avoid implicit conversions and ambiguous overload resolution.
OtherTypeThe type to compare the non_null to. It must not be a instantiation of non_null. held_pointer must be comparable to OtherType .
Parameters
lhsThe first value being compared
rhsThe second value being compared
Returns
The result of the comparison of the held pointer of lhs to the other value

◆ swap

template<typename P>
template<typename U = P, constraints< std::enable_if_t< is_swappable_v< P > > > = nullptr>
void swap ( non_null< P > & lhs,
non_null< P > & rhs )
friend

Swaps two non_null .

Template Parameters
UMust satisfy arene::base::is_swappable_v
Parameters
lhsThe left-hand non_null to swap.
rhsThe right-hand non_null to swap.
Postcondition
Equivalent to calling lhs.swap(rhs)
See also
arene::base::non_null::swap

Member Data Documentation

◆ pointer

template<typename P>
using arene::base::non_null< P >::pointer

The type of a raw pointer to the element pointed to by the non_null .


The documentation for this class was generated from the following file: