15template <
typename T,
typename Deleter>
18 PtrStore() noexcept : PtrStore(
nullptr) {}
21 ~PtrStore() { free(); }
23 PtrStore(
const PtrStore &) =
delete;
24 PtrStore &operator=(
const PtrStore &) =
delete;
28 : m_ptr(other.release()), m_deleter(std::move(other.m_deleter)) {}
33 m_deleter = std::move(other.m_deleter);
34 m_ptr = other.release();
40 bool valid()
const {
return m_ptr; }
42 operator bool()
const {
return valid(); }
50 std::string_view
str() const noexcept
51 requires std::same_as<T,
char> {
return m_ptr ? :
""; }
54 const T *
get() const noexcept {
return m_ptr; }
56 T *
get() noexcept {
return m_ptr; }
60 const T *
operator*() const noexcept {
return m_ptr; }
68 return std::exchange(m_ptr,
nullptr);
94 [[no_unique_address]] Deleter m_deleter;
97template<
typename T,
typename Deleter>
98requires std::same_as<T, char>
101 return os << err.str();
The Deleter for UniqueHolder types.
Definition Unique.h:15
A store for a pointer which is freed in the destructor using sqlite3_free()
Definition PtrStore.h:16
void reset(T *t=nullptr)
Set the pointer to t.
Definition PtrStore.h:72
PtrStore(PtrStore &&other) noexcept
Move constructor.
Definition PtrStore.h:27
bool operator!() const
! wrapper around valid()
Definition PtrStore.h:44
std::string_view str() const noexcept
Return the current pointer as string.
Definition PtrStore.h:50
T * release()
Return the pointer and stop owning it.
Definition PtrStore.h:67
T * get() noexcept
Get the stored pointer.
Definition PtrStore.h:56
const T * operator->() const noexcept
Get the stored pointer.
Definition PtrStore.h:64
bool valid() const
Does this instance hold a valid pointer?
Definition PtrStore.h:40
const T * get() const noexcept
Get the stored pointer.
Definition PtrStore.h:54
T * operator*() noexcept
Get the stored pointer.
Definition PtrStore.h:58
PtrStore & operator=(PtrStore &&other) noexcept
Move assignment.
Definition PtrStore.h:30
T * operator->() noexcept
Get the stored pointer.
Definition PtrStore.h:62
T ** ptr() noexcept
Get a pointer to the internal pointer.
Definition PtrStore.h:83
PtrStore(T *t) noexcept
Construct a new PtrStore with pointer set to t.
Definition PtrStore.h:20
const T * operator*() const noexcept
Get the stored pointer.
Definition PtrStore.h:60