From 69efb6291c7343e936f2ddce622990ed018b7fdb Mon Sep 17 00:00:00 2001 From: Lukas <116069013+lukasx999@users.noreply.github.com> Date: Thu, 14 Aug 2025 17:16:28 +0200 Subject: [PATCH] memory: smart pointer factories should not be static (#72) --- include/hyprutils/memory/Atomic.hpp | 8 ++------ include/hyprutils/memory/Casts.hpp | 4 +++- include/hyprutils/memory/SharedPtr.hpp | 6 ++---- include/hyprutils/memory/UniquePtr.hpp | 8 +++----- include/hyprutils/memory/WeakPtr.hpp | 4 +--- 5 files changed, 11 insertions(+), 19 deletions(-) diff --git a/include/hyprutils/memory/Atomic.hpp b/include/hyprutils/memory/Atomic.hpp index c4998a7..77505a9 100644 --- a/include/hyprutils/memory/Atomic.hpp +++ b/include/hyprutils/memory/Atomic.hpp @@ -83,9 +83,7 @@ namespace Hyprutils::Memory { std::swap(m_ptr, ref.m_ptr); } - CAtomicSharedPointer() noexcept { - ; // empty - } + CAtomicSharedPointer() noexcept = default; CAtomicSharedPointer(std::nullptr_t) noexcept { ; // empty @@ -262,9 +260,7 @@ namespace Hyprutils::Memory { m_ptr = ref.m_ptr; } - CAtomicWeakPointer() noexcept { - ; // empty - } + CAtomicWeakPointer() noexcept = default; CAtomicWeakPointer(std::nullptr_t) noexcept { ; // empty diff --git a/include/hyprutils/memory/Casts.hpp b/include/hyprutils/memory/Casts.hpp index 6f76d63..a40af73 100644 --- a/include/hyprutils/memory/Casts.hpp +++ b/include/hyprutils/memory/Casts.hpp @@ -26,4 +26,6 @@ namespace Hyprutils::Memory { constexpr To bc(const From& from) noexcept { return std::bit_cast(from); } -} \ No newline at end of file +} + + diff --git a/include/hyprutils/memory/SharedPtr.hpp b/include/hyprutils/memory/SharedPtr.hpp index a523def..3b1b3ca 100644 --- a/include/hyprutils/memory/SharedPtr.hpp +++ b/include/hyprutils/memory/SharedPtr.hpp @@ -61,9 +61,7 @@ namespace Hyprutils { } /* creates an empty shared pointer with no implementation */ - CSharedPointer() noexcept { - ; // empty - } + CSharedPointer() noexcept = default; /* creates an empty shared pointer with no implementation */ CSharedPointer(std::nullptr_t) noexcept { @@ -184,7 +182,7 @@ namespace Hyprutils { }; template - static CSharedPointer makeShared(Args&&... args) { + [[nodiscard]] inline CSharedPointer makeShared(Args&&... args) { return CSharedPointer(new U(std::forward(args)...)); } diff --git a/include/hyprutils/memory/UniquePtr.hpp b/include/hyprutils/memory/UniquePtr.hpp index 676b945..4d95934 100644 --- a/include/hyprutils/memory/UniquePtr.hpp +++ b/include/hyprutils/memory/UniquePtr.hpp @@ -42,9 +42,7 @@ namespace Hyprutils { } /* creates an empty unique pointer with no implementation */ - CUniquePointer() noexcept { - ; // empty - } + CUniquePointer() noexcept = default; /* creates an empty unique pointer with no implementation */ CUniquePointer(std::nullptr_t) noexcept { @@ -136,7 +134,7 @@ namespace Hyprutils { }; template - static CUniquePointer makeUnique(Args&&... args) { + [[nodiscard]] inline CUniquePointer makeUnique(Args&&... args) { return CUniquePointer(new U(std::forward(args)...)); } } @@ -147,4 +145,4 @@ struct std::hash> { std::size_t operator()(const Hyprutils::Memory::CUniquePointer& p) const noexcept { return std::hash{}(p.impl_); } -}; \ No newline at end of file +}; diff --git a/include/hyprutils/memory/WeakPtr.hpp b/include/hyprutils/memory/WeakPtr.hpp index 8b734d0..35d3ac6 100644 --- a/include/hyprutils/memory/WeakPtr.hpp +++ b/include/hyprutils/memory/WeakPtr.hpp @@ -102,9 +102,7 @@ namespace Hyprutils { } /* create an empty weak ptr */ - CWeakPointer() { - ; - } + CWeakPointer() noexcept = default; ~CWeakPointer() { decrementWeak();