5#ifndef INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_POINTER_NON_NULL_HPP_
6#define INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_POINTER_NON_NULL_HPP_
19#include "arene/base/pointer/detail/to_address.hpp"
20#include "arene/base/pointer/detail/type_traits.hpp"
21#include "arene/base/stdlib_choice/cstddef.hpp"
22#include "arene/base/stdlib_choice/decay.hpp"
23#include "arene/base/stdlib_choice/declval.hpp"
24#include "arene/base/stdlib_choice/enable_if.hpp"
25#include "arene/base/stdlib_choice/forward.hpp"
26#include "arene/base/stdlib_choice/hash.hpp"
27#include "arene/base/stdlib_choice/ignore.hpp"
28#include "arene/base/stdlib_choice/is_assignable.hpp"
29#include "arene/base/stdlib_choice/is_constructible.hpp"
30#include "arene/base/stdlib_choice/is_pointer.hpp"
31#include "arene/base/stdlib_choice/is_same.hpp"
32#include "arene/base/stdlib_choice/move.hpp"
33#include "arene/base/stdlib_choice/pointer_traits.hpp"
34#include "arene/base/stdlib_choice/remove_cv.hpp"
61namespace operators_detail {
69template <
typename Self,
typename Other>
70constexpr bool eligible_for_reversed_equals_with_v<non_null<Self>,
non_null<Other>> =
false;
105 static_assert(pointer::detail::is_pointer_like_v<P>,
"non_null is only defined for pointer-like types.");
157 ptr_(
std::forward<U>(ptr_value)) {
175 ptr_(copy_from.
unwrap()) {}
221 ptr_ = copy_from.unwrap();
260 template <typename U = held_pointer, constraints<std::enable_if_t<std::is_pointer<U>::value>> =
nullptr>
265 template <typename U = held_pointer, constraints<std::enable_if_t<!std::is_pointer<U>::value>> =
nullptr>
269 return ::arene::base::pointer::detail::to_address(ptr_);
288 template <typename U = held_pointer, constraints<std::enable_if_t<!std::is_pointer<U>::value>> =
nullptr>
346 template <
typename U = P, constra
ints<std::enable_if_t<is_swappable_v<P>>> =
nullptr>
361 template <
typename U = P, constra
ints<std::enable_if_t<is_swappable_v<P>>> =
nullptr>
375 template <
typename U = element_type,
typename = std::enable_if_t<!std::is_same<std::remove_cv_t<U>,
void>::value>>
387 template <
typename U = element_type,
typename = std::enable_if_t<!std::is_same<std::remove_cv_t<U>,
void>::value>>
399 template <typename U = held_pointer, constraints<std::enable_if_t<!std::is_pointer<U>::value>> =
nullptr>
401 return ptr_ !=
nullptr;
403 template <typename U = held_pointer, constraints<std::enable_if_t<std::is_pointer<U>::value>> =
nullptr>
433 template <typename U = held_pointer, constraints<std::enable_if_t<!std::is_pointer<U>::value>> =
nullptr>
458 ) const& noexcept(
std::is_nothrow_constructible<U,
held_pointer const&>::value) {
459 return static_cast<U
>(ptr_);
491 return lhs.unwrap() == rhs.unwrap();
509 typename NonNullType,
516 return lhs.unwrap() == rhs;
576 template <typename Dummy = held_pointer, constraints<std::enable_if_t<!std::is_pointer<Dummy>::value>> =
nullptr>
580 return strong_ordering::equal;
582 return strong_ordering::greater;
588 template <typename Dummy = held_pointer, constraints<std::enable_if_t<std::is_pointer<Dummy>::value>> =
nullptr>
591 return strong_ordering::greater;
597 template <
typename I>
599 template <
typename I>
601 template <
typename I>
603 template <
typename I>
constexpr generic_ordering_from_three_way_compare_and_equals() noexcept=default
A pointer type which is never nullptr.
Definition non_null.hpp:104
constexpr auto operator--() -> non_null &=delete
Pointer arithmetic is explicitly deleted.
typedef pointer
The type of a raw pointer to the element pointed to by the non_null .
Definition non_null.hpp:117
constexpr auto operator=(U &&new_ptr) noexcept(std::is_nothrow_assignable< held_pointer &, U >::value) -> non_null &
Assignment from a pointer type.
Definition non_null.hpp:203
constexpr void swap(non_null &swap_with) noexcept(is_nothrow_swappable_v< P >)
Swaps this with another non_null .
Definition non_null.hpp:347
constexpr non_null(std::nullptr_t)=delete
non_null cannot be constructed from a literal nullptr .
ARENE_NODISCARD constexpr auto unwrap() const &noexcept -> held_pointer const &
Definition non_null.hpp:284
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 hel...
Definition non_null.hpp:565
ARENE_NODISCARD constexpr auto get() const noexcept -> held_pointer
Gets a pointer to the pointed-to element.
Definition non_null.hpp:261
constexpr auto operator[](I) const =delete
Pointer arithmetic is explicitly deleted.
constexpr auto operator[](I)=delete
Pointer arithmetic is explicitly deleted.
friend constexpr void swap(non_null &lhs, non_null &rhs) noexcept(noexcept(lhs.swap(rhs)))
Swaps two non_null .
Definition non_null.hpp:362
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.
Definition non_null.hpp:310
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...
Definition non_null.hpp:515
constexpr auto operator=(non_null const &) -> non_null &=default
Default copy assignment.
ARENE_NODISCARD constexpr auto unwrap() &&noexcept -> held_pointer &&
Gets the held pointer backing the non_null.
Definition non_null.hpp:289
constexpr non_null(non_null< U > &&move_from) noexcept(std::is_nothrow_constructible< held_pointer, U && >::value)
Move constructor from non_null.
Definition non_null.hpp:188
P held_pointer
The pointer type being wrapped by the non_null .
Definition non_null.hpp:112
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.
Definition non_null.hpp:589
constexpr auto operator-(I const &) const -> non_null=delete
Pointer arithmetic is explicitly deleted.
constexpr non_null(non_null const &)=default
Default copy constructor.
constexpr void reset(std::nullptr_t) noexcept=delete
Resetting to a nullptr literal is not supported.
ARENE_NODISCARD constexpr auto operator*() const noexcept ->
Dereference operator.
Definition non_null.hpp:388
constexpr auto operator+(I const &) const -> non_null=delete
Pointer arithmetic is explicitly deleted.
ARENE_NODISCARD constexpr auto operator!() const noexcept -> bool
Boolean negation operator, equivalent to a == comparison to nullptr.
Definition non_null.hpp:415
~non_null()=default
Default destructor.
constexpr non_null(U &&ptr_value) noexcept(std::is_nothrow_constructible< held_pointer, U >::value)
Construction from a pointer type.
Definition non_null.hpp:155
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 p...
Definition non_null.hpp:547
constexpr auto operator++() -> non_null &=delete
Pointer arithmetic is explicitly deleted.
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.
Definition non_null.hpp:529
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.
Definition non_null.hpp:577
constexpr non_null(non_null< U > const ©_from) noexcept(std::is_nothrow_constructible< held_pointer, U const & >::value)
Copy constructor from non_null.
Definition non_null.hpp:172
constexpr auto operator=(non_null< U > &&move_from) noexcept(std::is_nothrow_assignable< held_pointer &, U && >::value) -> non_null &
Move assignment from non_null.
Definition non_null.hpp:235
ARENE_NODISCARD constexpr auto operator->() const noexcept -> pointer
Arrow operator.
Definition non_null.hpp:376
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.
Definition non_null.hpp:331
constexpr auto operator=(non_null< U > const ©_from) noexcept(std::is_nothrow_assignable< held_pointer &, U const & >::value) -> non_null &
Copy assignment from non_null.
Definition non_null.hpp:219
constexpr auto operator--(int) -> non_null &=delete
Pointer arithmetic is explicitly deleted.
typename std::pointer_traits< held_pointer >::element_type element_type
The type of the element pointed to.
Definition non_null.hpp:114
constexpr auto operator=(non_null &&) -> non_null &=default
Default move assignment.
ARENE_NODISCARD constexpr auto get() const noexcept ->
Gets a pointer to the pointed-to element.
Definition non_null.hpp:266
constexpr non_null(non_null &&)=default
Default move constructor.
constexpr non_null()=delete
non_null cannot be default constructed
constexpr auto operator++(int) -> non_null &=delete
Pointer arithmetic is explicitly deleted.
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 po...
Definition non_null.hpp:489
static constexpr value_type value
Definition integral_constant.hpp:34
provides a uniform interface to pointer-like types
Definition pointer_traits.hpp:185
#define ARENE_INVARIANT(condition)
Check that an invariant holds, and terminate the application if it does not.
Definition contract.hpp:161
#define ARENE_PRECONDITION(condition)
Check that a precondition holds, and terminate the application if it does not.
Definition contract.hpp:150
static ARENE_MAYBE_UNUSED constexpr auto const & swap
A Customization Point Object implementation of the constexpr compatible std::swap from C++17.
Definition swap.hpp:130
Definition accumulate.hpp:37
ARENE_NODISCARD constexpr auto make_non_null(P &&ptr) noexcept -> non_null< std::decay_t< P > >
Factory function to deduce the type of a non_null.
Definition non_null.hpp:629
constexpr bool is_nothrow_swappable_v
Trait query indicating if a type can be noexcept-swapped.
constexpr auto move(InIterator first, InIterator last, OutIterator output) noexcept(noexcept(*first++) &&noexcept(output++) &&//CODEQLFP(EXP52-CPP) CODEQLFP(A5-2-6) noexcept(first !=last) &&//CODEQLFP(A5-2-6) std::is_nothrow_assignable<, typename std::iterator_traits< InIterator >::value_type >::value) -> OutIterator
Moves the elements in the range [first, last), to another range beginning at output,...
Definition move.hpp:46
constexpr bool is_instantiation_of_v
Definition is_instantiation_of.hpp:16
non_null< T * > non_null_ptr
Alias for a non_null which holds a raw pointer.
Definition non_null.hpp:642
strong_ordering_detail::strong_ordering strong_ordering
The enumeration specifying the result of an ordering comparison.
Definition strong_ordering.hpp:147
three_way_compare_detail::compare_three_way compare_three_way
Function object that does a three-way comparison between operands, equivalent to std::compare_three_w...
Definition compare_three_way.hpp:214
constexpr bool is_non_null_v
Trait that deduces if a type is an non_null to any type.
Definition non_null.hpp:59
typename constraints_impl::constraints< EnableIfs... >::type constraints
Helper used to express template constraints in a consistent way using std::enable_if_t.
Definition constraints.hpp:51
Definition accumulate.hpp:36
typedef nullptr_t
The type of nullptr.
Definition cstddef.hpp:33
constexpr auto move(T &&value) noexcept -> remove_reference_t< T > &&
Cast a value to an rvalue.
Definition move.hpp:30
typename enable_if< Condition, Type >::type enable_if_t
Type alias to support constraining templates. Is an alias for the specified type if the Condition is ...
Definition enable_if.hpp:41
auto declval() noexcept -> T &&
A dummy function that is declared but not defined, with a user-specified return type,...
static constexpr auto const & ignore
An object to which anything can be assigned, which ignores the assigned value.
Definition ignore.hpp:72
constexpr auto forward(remove_reference_t< T > &value) noexcept -> T &&
Cast a value to an rvalue if T is an rvalue or rvalue reference, otherwise forward an lvalue referenc...
Definition forward.hpp:24
#define ARENE_NODISCARD
An alias for [[nodiscard]] , or a no-op if the attribute is not supported.
Definition nodiscard.hpp:26
constexpr auto operator()(::arene::base::non_null< P > const &ptr) const noexcept -> size_t
Hash the pointer.
Definition non_null.hpp:662
hash function primary template
Definition hash.hpp:179