4#ifndef GREM_CORE_DATA_UNIQUE_POINTER_HPP
5#define GREM_CORE_DATA_UNIQUE_POINTER_HPP
19template <
typename T,
typename Deleter>
20struct deleter_pointer_type {
24template <
typename T,
typename Deleter>
25requires(
requires {
typename Deleter::pointer; })
struct deleter_pointer_type<T, Deleter> {
26 using type =
typename Deleter::pointer;
63 constexpr void operator()(U* handle)
const noexcept requires(std::is_convertible_v<U (*)[], T (*)[]>) {
76template <
typename T,
typename Deleter = DefaultDelete<T>>
80 using pointer =
typename detail::deleter_pointer_type<T, std::remove_reference_t<Deleter>>::type;
100 template <
typename... Args>
125 template <
typename U,
typename OtherDeleter>
127 requires(!std::is_same_v<T, U> && std::is_convertible_v<typename UniquePointer<U, OtherDeleter>::pointer,
pointer>)
146 constexpr explicit operator bool() const noexcept {
147 return static_cast<bool>(handle);
162 return handle.get() == other.handle.get();
172 [[nodiscard]]
constexpr bool operator==(std::nullptr_t other)
const noexcept {
188 handle.reset(newPointer);
211 return handle.release();
232 return handle.get_deleter();
240 [[nodiscard]]
constexpr const Deleter&
get_deleter() const noexcept {
241 return handle.get_deleter();
268 [[nodiscard]]
constexpr decltype(
auto)
operator*()
const noexcept requires(!std::is_void_v<T>) {
269 return *handle.get();
284template <
typename T,
typename Deleter>
288 using pointer =
typename detail::deleter_pointer_type<T, std::remove_reference_t<Deleter>>::type;
342 constexpr explicit operator bool() const noexcept {
343 return static_cast<bool>(handle);
358 return handle.get() == other.handle.get();
368 [[nodiscard]]
constexpr bool operator==(std::nullptr_t other)
const noexcept {
384 handle.reset(newPointer);
407 return handle.release();
429 return handle.get_deleter();
437 [[nodiscard]]
constexpr const Deleter&
get_deleter() const noexcept {
438 return handle.get_deleter();
453 [[nodiscard]]
constexpr decltype(
auto)
operator[](std::size_t index)
const noexcept requires(!std::is_void_v<T>) {
454 return handle.get()[index];
constexpr DefaultDelete() noexcept=default
constexpr void operator()(U *handle) const noexcept
Definition UniquePointer.hpp:63
constexpr DefaultDelete() noexcept=default
constexpr void operator()(T *handle) const noexcept
Definition UniquePointer.hpp:44
Generic nullable RAII resource handle with exclusive ownership of a resource that is automatically de...
Definition UniqueHandle.hpp:26
Deleter deleter_type
Deleter type.
Definition UniquePointer.hpp:294
T element_type
Object type.
Definition UniquePointer.hpp:291
constexpr pointer get() const noexcept
Get the underlying array pointer.
Definition UniquePointer.hpp:419
constexpr void reset(pointer newPointer=nullptr) noexcept
Destroy the array associated with this pointer, if any, and take ownership of a new array,...
Definition UniquePointer.hpp:383
static constexpr UniquePointer create(std::size_t size)
Allocate an array of default-initialized elements of the associated type and wrap it in a pointer wit...
Definition UniquePointer.hpp:308
constexpr Deleter & get_deleter() noexcept
Get the current deleter.
Definition UniquePointer.hpp:428
constexpr pointer release() noexcept
Relinquish ownership of the associated array.
Definition UniquePointer.hpp:406
constexpr const Deleter & get_deleter() const noexcept
Get the current deleter.
Definition UniquePointer.hpp:437
constexpr bool operator==(const UniquePointer &other) const noexcept
Compare this pointer against another for equality of the underlying address.
Definition UniquePointer.hpp:357
constexpr UniquePointer(pointer pointer, Deleter deleter=Deleter()) noexcept
Construct a pointer that takes ownership of an existing array.
Definition UniquePointer.hpp:333
constexpr UniquePointer() noexcept=default
Construct a null pointer without an associated array.
constexpr bool operator==(std::nullptr_t other) const noexcept
Check if this pointer is null and has no associated array.
Definition UniquePointer.hpp:368
constexpr pointer get() const noexcept
Get the underlying pointer.
Definition UniquePointer.hpp:222
constexpr bool operator==(std::nullptr_t other) const noexcept
Check if this pointer is null and has no associated object.
Definition UniquePointer.hpp:172
T element_type
Object type.
Definition UniquePointer.hpp:83
constexpr UniquePointer(UniquePointer< U, OtherDeleter > &&other) noexcept
Construct a pointer from another pointer of a derived type, taking ownership of its underlying object...
Definition UniquePointer.hpp:126
constexpr const Deleter & get_deleter() const noexcept
Get the current deleter.
Definition UniquePointer.hpp:240
constexpr UniquePointer() noexcept=default
Construct a null pointer without an associated object.
constexpr pointer release() noexcept
Relinquish ownership of the associated object.
Definition UniquePointer.hpp:210
constexpr UniquePointer(pointer pointer, Deleter deleter=Deleter()) noexcept
Construct a pointer that takes ownership of an existing object pointer.
Definition UniquePointer.hpp:137
constexpr bool operator==(const UniquePointer &other) const noexcept
Compare this pointer against another for equality of the underlying address.
Definition UniquePointer.hpp:161
Deleter deleter_type
Deleter type.
Definition UniquePointer.hpp:86
constexpr Deleter & get_deleter() noexcept
Get the current deleter.
Definition UniquePointer.hpp:231
static constexpr UniquePointer create(Args &&... args)
Allocate and construct an object of the associated type and wrap it in a pointer with unique ownershi...
Definition UniquePointer.hpp:101
constexpr void reset(pointer newPointer=nullptr) noexcept
Destroy the object associated with this pointer, if any, and take ownership of a new object pointer,...
Definition UniquePointer.hpp:187
constexpr pointer operator->() const noexcept
Access the associated object by pointer.
Definition UniquePointer.hpp:254
Definition concepts.hpp:106
@ T
't'
Definition keyboard.hpp:90
constexpr auto move(input_range auto &&range, auto outputIterator)
Definition algorithms.hpp:669