Add swap() and support std::hash

This commit is contained in:
josh committed 2026-02-24 19:53:59 -05:00
1 parent 464527a34d
commit d2b6755704
2 files changed
+43

No files matched your search

+20
View File
@@ -23,6 +23,7 @@
#pragma once
#include <atomic>
#include <functional>
#include <type_traits>
/**
@@ -118,6 +119,13 @@ public:
other.ptr = nullptr;
}
void swap(rcp & other) noexcept
{
T * tmp = ptr;
ptr = other.ptr;
other.ptr = tmp;
}
void reset()
{
if (ptr)
@@ -179,6 +187,18 @@ public:
friend rcp<V> rcp_dynamic_cast(rcp<W> && other);
};
namespace std
{
template <typename T>
struct hash<rcp<T>>
{
size_t operator()(const rcp<T> & p) const noexcept
{
return hash<const void *>()(static_cast<const void *>(p.get_raw()));
}
};
}
template <typename T, typename U>
rcp<T> rcp_dynamic_cast(const rcp<U> & other)
{