19#ifndef INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_POINTER_NON_OWNING_PTR_HPP_
20#define INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_POINTER_NON_OWNING_PTR_HPP_
23#include "arene/base/compare/operators.hpp"
24#include "arene/base/compiler_support/attributes.hpp"
25#include "arene/base/constraints/constraints.hpp"
26#include "arene/base/contracts/contract.hpp"
27#include "arene/base/stdlib_choice/cstddef.hpp"
28#include "arene/base/stdlib_choice/enable_if.hpp"
29#include "arene/base/stdlib_choice/hash.hpp"
30#include "arene/base/stdlib_choice/is_convertible.hpp"
31#include "arene/base/stdlib_choice/is_pointer.hpp"
32#include "arene/base/stdlib_choice/is_reference.hpp"
33#include "arene/base/stdlib_choice/remove_const.hpp"
34#include "arene/base/stdlib_choice/remove_pointer.hpp"
35#include "arene/base/type_traits/is_instantiation_of.hpp"
72class non_owning_ptr : full_ordering_operators_from_less_than_and_equals<non_owning_ptr<T>> {
75 !std::is_pointer<T>::value,
76 "Cannot create an object pointer to a raw pointer. Perhaps you "
77 "meant non_owning_ptr<T> for T* semantics, or "
78 "non_owning_ptr<non_owning_ptr<T>> for T** semantics?"
81 !std::is_reference<T>::value,
82 "Cannot create an object pointer to a reference. Perhaps you "
83 "meant non_owning_ptr<T> rather than non_owning_ptr<T&>?"
88 using ordering_base = full_ordering_operators_from_less_than_and_equals<non_owning_ptr<T>>;
100 using element_type = T;
104 using reference = T&;
119 constexpr non_owning_ptr(std::nullptr_t)
noexcept
129 constexpr non_owning_ptr(pointer new_ptr)
noexcept
143 typename U = element_type,
144 constraints<std::enable_if_t<std::is_convertible<
typename non_owning_ptr<U>::pointer, pointer>::value>> =
nullptr>
146 constexpr non_owning_ptr(non_owning_ptr<U> new_ptr)
noexcept
147 : non_owning_ptr(new_ptr.get()) {}
158 typename U = pointer,
160 std::enable_if_t<std::is_pointer<U>::value>,
161 std::enable_if_t<std::is_convertible<U, pointer>::value>> =
nullptr>
163 constexpr non_owning_ptr(U new_ptr)
noexcept
164 : non_owning_ptr(
static_cast<pointer>(new_ptr)) {}
173 ARENE_NODISCARD
constexpr auto get()
const noexcept -> pointer {
return ptr_; }
184 typename U = pointer,
186 std::enable_if_t<std::is_pointer<U>::value>,
187 std::enable_if_t<std::is_convertible<U, pointer>::value>> =
nullptr>
188 constexpr void reset(U new_ptr =
nullptr) {
189 ptr_ =
static_cast<pointer>(new_ptr);
199 ARENE_NODISCARD
constexpr auto operator*()
const noexcept -> reference {
return *checked_get(); }
208 ARENE_NODISCARD
constexpr auto operator->()
const noexcept -> pointer {
return checked_get(); }
219 constraints<std::enable_if_t<!is_non_owning_ptr_v<U>>, std::enable_if_t<std::is_convertible<pointer, U>::value>> =
222 constexpr explicit operator U()
const noexcept {
233 ARENE_NODISCARD
constexpr explicit operator
bool()
const noexcept {
return get() !=
nullptr; }
241 ARENE_NODISCARD
constexpr auto operator!()
const noexcept ->
bool {
return !
static_cast<
bool>(*
this); }
253 ARENE_NODISCARD
friend constexpr auto operator==(non_owning_ptr
const& lhs, non_owning_ptr
const& rhs)
noexcept
255 return lhs.get() == rhs.get();
258 ARENE_NODISCARD
friend constexpr auto operator<(non_owning_ptr
const& lhs, non_owning_ptr
const& rhs)
noexcept
260 return lhs.get() < rhs.get();
271 template <
typename I>
272 constexpr auto operator[](I) =
delete;
273 template <
typename I>
275 template <
typename I>
276 constexpr auto operator+(I
const&)
const -> non_owning_ptr =
delete;
277 template <
typename I>
278 constexpr auto operator-(I
const&)
const -> non_owning_ptr =
delete;
279 constexpr auto operator++() -> non_owning_ptr& =
delete;
281 constexpr auto operator++(
int) -> non_owning_ptr& =
delete;
283 constexpr auto operator--() -> non_owning_ptr& =
delete;
285 constexpr auto operator--(
int) -> non_owning_ptr& =
delete;
297 ARENE_NODISCARD
constexpr auto checked_get()
const -> pointer {
298 ARENE_PRECONDITION(ptr_);
336 return hash<
typename arene::
base::non_owning_ptr<T>::pointer>()(ptr.get());
constexpr auto operator+(I const &) const -> non_owning_ptr=delete
Pointer arithmetic is explicitly deleted.
constexpr auto operator--() -> non_owning_ptr &=delete
Pointer arithmetic is explicitly deleted.
constexpr auto operator++() -> non_owning_ptr &=delete
Pointer arithmetic is explicitly deleted.
constexpr auto operator-(I const &) const -> non_owning_ptr=delete
Pointer arithmetic is explicitly deleted.
constexpr auto operator[](I) const =delete
Pointer arithmetic is explicitly deleted.
constexpr auto operator++(int) -> non_owning_ptr &=delete
Pointer arithmetic is explicitly deleted.
constexpr auto operator--(int) -> non_owning_ptr &=delete
Pointer arithmetic is explicitly deleted.
constexpr non_owning_ptr() noexcept=default
Default, trivial constructor.
Definition array_exceptions_disabled.cpp:11
constexpr bool is_non_owning_ptr_v
Trait that deduces if a type is an non_owning_ptr to any type.
Definition non_owning_ptr.hpp:55
Copyright 2026, Toyota Motor Corporation.
Definition array_exceptions_disabled.cpp:10
constexpr auto operator()(::arene::base::non_owning_ptr< T > const &ptr) const noexcept -> size_t
Calculate the hash of the pointer.
Definition non_owning_ptr.hpp:335
constexpr auto operator()(::arene::base::result< void, E > const &value) const noexcept(noexcept(hash< E >{}(std::declval< E const & >()))) -> std::size_t
Calculate the hash of a result.
Definition result.hpp:1827
hash function primary template
Definition hash.hpp:138