memory: fix clangd warnings

modernize validHierarchy and isConstructible, mark move operator
noexcept, use default destructor instead of {}, __deleter is a reserved
name, remove a underscore.

as per clangd docs.
The C standard additionally reserves names beginning with a double underscore,
while the C++ standard strengthens this to reserve names with a double underscore occurring anywhere.
This commit is contained in:
Tom Englund 2025-09-26 23:56:18 +02:00 committed by Vaxry
parent 427332a7ca
commit 05f0fb2774
5 changed files with 15 additions and 15 deletions

View file

@ -50,9 +50,9 @@ namespace Hyprutils::Memory {
template <typename T> template <typename T>
class CAtomicSharedPointer { class CAtomicSharedPointer {
template <typename X> template <typename X>
using isConstructible = typename std::enable_if<std::is_constructible<T&, X&>::value>::type; using isConstructible = std::enable_if_t<std::is_constructible_v<T&, X&>>;
template <typename X> template <typename X>
using validHierarchy = typename std::enable_if<std::is_assignable<CAtomicSharedPointer<T>&, X>::value, CAtomicSharedPointer&>::type; using validHierarchy = std::enable_if_t<std::is_assignable_v<CAtomicSharedPointer<T>&, X>, CAtomicSharedPointer&>;
public: public:
explicit CAtomicSharedPointer(Impl_::impl_base* impl) noexcept : m_ptr(impl) {} explicit CAtomicSharedPointer(Impl_::impl_base* impl) noexcept : m_ptr(impl) {}
@ -221,9 +221,9 @@ namespace Hyprutils::Memory {
class CAtomicWeakPointer { class CAtomicWeakPointer {
template <typename X> template <typename X>
using isConstructible = typename std::enable_if<std::is_constructible<T&, X&>::value>::type; using isConstructible = std::enable_if_t<std::is_constructible_v<T&, X&>>;
template <typename X> template <typename X>
using validHierarchy = typename std::enable_if<std::is_assignable<CAtomicWeakPointer<T>&, X>::value, CAtomicWeakPointer&>::type; using validHierarchy = std::enable_if_t<std::is_assignable_v<CAtomicWeakPointer<T>&, X>, CAtomicWeakPointer&>;
public: public:
CAtomicWeakPointer(const CAtomicWeakPointer<T>& ref) { CAtomicWeakPointer(const CAtomicWeakPointer<T>& ref) {

View file

@ -8,7 +8,7 @@ namespace Hyprutils {
namespace Impl_ { namespace Impl_ {
class impl_base { class impl_base {
public: public:
virtual ~impl_base() {}; virtual ~impl_base() = default;
virtual void inc() noexcept = 0; virtual void inc() noexcept = 0;
virtual void dec() noexcept = 0; virtual void dec() noexcept = 0;
@ -57,13 +57,13 @@ namespace Hyprutils {
// this way, weak pointers will still be able to // this way, weak pointers will still be able to
// reference and use, but no longer create shared ones. // reference and use, but no longer create shared ones.
_destroying = true; _destroying = true;
__deleter(_data); _deleter(_data);
// now, we can reset the data and call it a day. // now, we can reset the data and call it a day.
_data = nullptr; _data = nullptr;
_destroying = false; _destroying = false;
} }
std::default_delete<T> __deleter{}; std::default_delete<T> _deleter{};
// //
virtual void inc() noexcept { virtual void inc() noexcept {

View file

@ -22,9 +22,9 @@ namespace Hyprutils {
class CSharedPointer { class CSharedPointer {
public: public:
template <typename X> template <typename X>
using validHierarchy = typename std::enable_if<std::is_assignable<CSharedPointer<T>&, X>::value, CSharedPointer&>::type; using validHierarchy = std::enable_if_t<std::is_assignable_v<CSharedPointer<T>&, X>, CSharedPointer&>;
template <typename X> template <typename X>
using isConstructible = typename std::enable_if<std::is_constructible<T&, X&>::value>::type; using isConstructible = std::enable_if_t<std::is_constructible_v<T&, X&>>;
/* creates a new shared pointer managing a resource /* creates a new shared pointer managing a resource
avoid calling. Could duplicate ownership. Prefer makeShared */ avoid calling. Could duplicate ownership. Prefer makeShared */
@ -95,7 +95,7 @@ namespace Hyprutils {
return *this; return *this;
} }
CSharedPointer& operator=(CSharedPointer&& rhs) { CSharedPointer& operator=(CSharedPointer&& rhs) noexcept {
std::swap(impl_, rhs.impl_); std::swap(impl_, rhs.impl_);
return *this; return *this;
} }

View file

@ -16,9 +16,9 @@ namespace Hyprutils {
class CUniquePointer { class CUniquePointer {
public: public:
template <typename X> template <typename X>
using validHierarchy = typename std::enable_if<std::is_assignable<CUniquePointer<T>&, X>::value, CUniquePointer&>::type; using validHierarchy = std::enable_if_t<std::is_assignable_v<CUniquePointer<T>&, X>, CUniquePointer&>;
template <typename X> template <typename X>
using isConstructible = typename std::enable_if<std::is_constructible<T&, X&>::value>::type; using isConstructible = std::enable_if_t<std::is_constructible_v<T&, X&>>;
/* creates a new unique pointer managing a resource /* creates a new unique pointer managing a resource
avoid calling. Could duplicate ownership. Prefer makeUnique */ avoid calling. Could duplicate ownership. Prefer makeUnique */
@ -62,7 +62,7 @@ namespace Hyprutils {
return *this; return *this;
} }
CUniquePointer& operator=(CUniquePointer&& rhs) { CUniquePointer& operator=(CUniquePointer&& rhs) noexcept {
std::swap(impl_, rhs.impl_); std::swap(impl_, rhs.impl_);
return *this; return *this;
} }

View file

@ -16,9 +16,9 @@ namespace Hyprutils {
class CWeakPointer { class CWeakPointer {
public: public:
template <typename X> template <typename X>
using validHierarchy = typename std::enable_if<std::is_assignable<CWeakPointer<T>&, X>::value, CWeakPointer&>::type; using validHierarchy = std::enable_if_t<std::is_assignable_v<CWeakPointer<T>&, X>, CWeakPointer&>;
template <typename X> template <typename X>
using isConstructible = typename std::enable_if<std::is_constructible<T&, X&>::value>::type; using isConstructible = std::enable_if_t<std::is_constructible_v<T&, X&>>;
/* create a weak ptr from a reference */ /* create a weak ptr from a reference */
template <typename U, typename = isConstructible<U>> template <typename U, typename = isConstructible<U>>