Add casting move constructor

This commit is contained in:
josh committed 2026-02-24 16:00:14 -05:00
1 parent 7880adef89
commit ddaae32525
2 files changed
+27 -1

No files matched your search

+10 -1
View File
@@ -31,6 +31,8 @@
template <typename T>
class rcp
{
template <typename U> friend class rcp;
private:
T * ptr = nullptr;
@@ -100,7 +102,7 @@ public:
/* Upcasting constructor: allows rcp<Derived> -> rcp<Base> */
template <typename U>
rcp(const rcp<U> & other) : ptr(static_cast<T *>(other.get_raw()))
rcp(const rcp<U> & other) : ptr(static_cast<T *>(other.ptr))
{
static_assert(std::is_base_of<T, U>::value, "rcp: implicit cast must be an upcast");
if (ptr)
@@ -109,6 +111,13 @@ public:
}
}
template <typename U>
rcp(rcp<U> && other) : ptr(static_cast<T *>(other.ptr))
{
static_assert(std::is_base_of<T, U>::value, "rcp: implicit cast must be an upcast");
other.ptr = nullptr;
}
T * get_raw() const
{
return ptr;