24 constexpr void operator()(T* pointer)
const {
delete pointer; }
27template<
typename T,
typename Deleter = DefaultDelete<T>>
40 constexpr explicit Box(T* pointer)
42 : m_pointer(pointer) {}
49 constexpr Box(T* pointer, Deleter
const& deleter)
51 : m_pointer(pointer), m_deleter(deleter) {}
53 template<concepts::MoveConstructible D = Deleter>
55 constexpr Box(T* pointer, D&& deleter) : m_pointer(pointer,
util::forward<D>(deleter)) {}
57 template<
typename D = Deleter>
61 template<
typename U,
typename E>
65 constexpr Box(
Box<U, E>&& other) : m_pointer(other.release()), m_deleter(util::forward<E>(other.get_deleter())) {}
73 reset(other.release());
74 m_deleter = util::forward<Deleter>(other.get_deleter());
78 template<
typename U,
typename E>
82 reset(other.release());
83 m_deleter = util::forward<Deleter>(other.get_deleter());
93 constexpr void reset(T* pointer =
nullptr) {
94 auto* old_pointer = m_pointer;
101 constexpr auto get() const -> T* {
return m_pointer; }
104 constexpr auto get_deleter() const -> Deleter const& {
return m_deleter; }
106 constexpr explicit operator bool()
const {
return !!m_pointer; }
117 constexpr auto begin() const -> T* {
return get(); }
118 constexpr auto end() const -> T* {
128 return const_cast<void*
>(
static_cast<void const volatile*
>(a.get())) ==
129 const_cast<void*
>(
static_cast<void const volatile*
>(b.get()));
134 return const_cast<void*
>(
static_cast<void const volatile*
>(a.
get())) <=>
135 const_cast<void*
>(
static_cast<void const volatile*
>(b.
get()));
140 return a ==
nullptr ? di::strong_ordering::equal : di::strong_ordering::greater;
145 T* m_pointer {
nullptr };
146 [[no_unique_address]] Deleter m_deleter {};
151 struct MakeBoxFunction {
152 template<
typename... Args>
153 requires(!concepts::LanguageArray<T> && concepts::ConstructibleFrom<T, Args...>)
155 if constexpr (concepts::FallibleAllocator<platform::DefaultAllocator>) {
156 auto* result = ::new (std::nothrow) T(util::forward<Args>(args)...);
160 return Box<T>(result);
162 auto* result = ::new T(util::forward<Args>(args)...);
164 return Box<T>(result);
171constexpr inline auto make_box = detail::MakeBoxFunction<T> {};
176using vocab::DefaultDelete;
#define DI_ASSERT(...)
Definition assert_bool.h:7
constexpr friend auto operator==(Box const &a, Box< U > const &b) -> bool
Definition box.h:127
constexpr auto end() const -> T *
Definition box.h:118
constexpr Box(T *pointer, Deleter const &deleter)
Definition box.h:49
constexpr Box(T *pointer, D &&deleter)
Definition box.h:55
constexpr Box(nullptr_t)
Definition box.h:36
constexpr friend auto operator<=>(Box const &a, nullptr_t)
Definition box.h:139
constexpr auto operator=(Box &&other) -> Box &requires(concepts::MoveAssignable< Deleter >)
Definition box.h:70
T Type
Definition box.h:30
constexpr auto get_deleter() -> Deleter &
Definition box.h:103
constexpr ~Box()
Definition box.h:67
auto operator=(Box const &) -> Box &=delete
constexpr friend auto operator==(Box const &a, nullptr_t) -> bool
Definition box.h:138
constexpr Box(T *pointer)
Definition box.h:40
constexpr auto release() -> T *
Definition box.h:92
constexpr friend auto operator<=>(Box const &a, Box< U > const &b)
Definition box.h:133
constexpr auto operator*() const -> T &
Definition box.h:108
constexpr auto operator=(nullptr_t) -> Box &
Definition box.h:87
constexpr friend auto tag_invoke(Tag< concepts::trivially_relocatable >, InPlaceType< Box >) -> bool
Definition box.h:143
constexpr auto begin() const -> T *
Definition box.h:117
constexpr auto get_deleter() const -> Deleter const &
Definition box.h:104
constexpr Box(Box< U, E > &&other)
Definition box.h:65
constexpr auto operator->() const -> T *
Definition box.h:112
constexpr void reset(T *pointer=nullptr)
Definition box.h:93
constexpr Box(Box &&other)
Definition box.h:45
Box(T *, meta::RemoveReference< D > &&)=delete
constexpr auto get() const -> T *
Definition box.h:101
Definition operations.h:19
Definition operations.h:99
Definition operations.h:34
Definition operations.h:24
Implicit conversion for this test refers to the ability to return a value of function from a type.
Definition operations.h:89
Definition language.h:110
Definition operations.h:46
Definition operations.h:43
constexpr auto invoke
Definition invoke.h:100
di::meta::Decay< decltype(T)> Tag
Definition tag_invoke.h:28
std::nullptr_t nullptr_t
Definition nullptr_t.h:12
constexpr auto exchange(T &object, U &&new_value) -> T
Definition exchange.h:8
constexpr auto make_box
Definition box.h:171
Unexpected(E &&) -> Unexpected< meta::UnwrapRefDecay< E > >
Definition any_storable.h:9
Definition in_place_type.h:5
constexpr DefaultDelete(DefaultDelete< U > const &)
Definition box.h:22
constexpr void operator()(T *pointer) const
Definition box.h:24