aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libs/kstd/kstd/bits/shared_ptr.hpp25
1 files changed, 24 insertions, 1 deletions
diff --git a/libs/kstd/kstd/bits/shared_ptr.hpp b/libs/kstd/kstd/bits/shared_ptr.hpp
index 7af0a00e..8d5dc1a8 100644
--- a/libs/kstd/kstd/bits/shared_ptr.hpp
+++ b/libs/kstd/kstd/bits/shared_ptr.hpp
@@ -360,7 +360,7 @@ namespace kstd
}
/**
- * @brief Constructor a shared_ptr from a weak_ptr. If other is not expired, constructs a shared_ptr which shares
+ * @brief Construct a shared_ptr from a weak_ptr. If other is not expired, constructs a shared_ptr which shares
* ownership of the object managed by other. Otherwise, constructs an empty shared_ptr.
*
* @param other The weak_ptr to construct from.
@@ -386,6 +386,23 @@ namespace kstd
}
}
+ //! Aliasing constructor.
+ //!
+ //! @tparam U The type of the object managed by other.
+ //! @param other The shared_ptr to share ownership with.
+ //! @param pointer The pointer this shared_ptr should own.
+ template<typename Y>
+ requires bits::is_shared_pointer_ctor_compatible<Y *, T *>::value
+ shared_ptr(shared_ptr<Y> const & other, T * pointer) noexcept
+ : m_storage{pointer}
+ , m_control_block{other.m_control_block}
+ {
+ if (m_control_block != nullptr)
+ {
+ ++(m_control_block->strong_count);
+ }
+ }
+
/**
* @brief Copy constructor.
*
@@ -734,6 +751,12 @@ namespace kstd
return shared_ptr<T>(new T(std::forward<Args>(args)...));
}
+ template<typename T, typename U>
+ [[nodiscard]] auto static_pointer_cast(shared_ptr<U> const & other) noexcept -> shared_ptr<T>
+ {
+ return shared_ptr<T>{other, static_cast<T *>(other.get())};
+ }
+
/**
* @brief Equality operator for shared_ptr. Two shared_ptr instances are equal if they point to the same object
* @tparam T, U Types of the managed objects of the shared_ptr instances being compared.