memory: Add force reinterpret constructor to shared pointer

This commit is contained in:
Lee Bousfield 2025-03-04 08:27:15 -06:00
parent 61a5382f4b
commit c3ddf46b2a
No known key found for this signature in database
GPG key ID: 51137D1C9B477CBD

View file

@ -16,6 +16,12 @@
namespace Hyprutils {
namespace Memory {
struct SForceReinterpret {
explicit SForceReinterpret() = default;
};
constexpr SForceReinterpret FORCE_REINTERPRET = SForceReinterpret();
template <typename T>
class CSharedPointer {
public:
@ -38,6 +44,12 @@ namespace Hyprutils {
increment();
}
template <typename U>
CSharedPointer(const CSharedPointer<U>& ref, SForceReinterpret) noexcept {
impl_ = ref.impl_;
increment();
}
CSharedPointer(const CSharedPointer& ref) noexcept {
impl_ = ref.impl_;
increment();
@ -144,7 +156,7 @@ namespace Hyprutils {
Impl_::impl_base* impl_ = nullptr;
private:
/*
/*
no-op if there is no impl_
may delete the stored object if ref == 0
may delete and reset impl_ if ref == 0 and weak == 0
@ -167,7 +179,7 @@ namespace Hyprutils {
impl_->inc();
}
/* destroy the pointed-to object
/* destroy the pointed-to object
if able, will also destroy impl */
void destroyImpl() {
// destroy the impl contents