aboutsummaryrefslogtreecommitdiff
path: root/libs
diff options
context:
space:
mode:
authorFelix Morgner <felix.morgner@ost.ch>2026-09-10 14:33:19 +0200
committerFelix Morgner <felix.morgner@ost.ch>2026-09-10 14:33:19 +0200
commit14ec8e92b45a2eae5bdb3d459cee9633ea129359 (patch)
treee25ec59134144bbdd00c451136b8425a75d89050 /libs
parentfcc2527351589b6e3a85e88d01f1d310165aa8af (diff)
downloadkernel-14ec8e92b45a2eae5bdb3d459cee9633ea129359.tar.xz
kernel-14ec8e92b45a2eae5bdb3d459cee9633ea129359.zip
kstd/memory: introduce observer_ptr casts
Diffstat (limited to 'libs')
-rw-r--r--libs/kstd/kstd/bits/observer_ptr.hpp42
1 files changed, 42 insertions, 0 deletions
diff --git a/libs/kstd/kstd/bits/observer_ptr.hpp b/libs/kstd/kstd/bits/observer_ptr.hpp
index d53ab5a0..d0c40549 100644
--- a/libs/kstd/kstd/bits/observer_ptr.hpp
+++ b/libs/kstd/kstd/bits/observer_ptr.hpp
@@ -160,6 +160,48 @@ namespace kstd
return observer_ptr<ElementType>{pointer};
}
+ template<typename T, typename U>
+ [[nodiscard]] constexpr auto static_pointer_cast(observer_ptr<U> const & other) noexcept -> observer_ptr<T>
+ {
+ return observer_ptr{static_cast<observer_ptr<T>::element_type *>(other.get())};
+ }
+
+ template<typename T, typename U>
+ [[nodiscard]] constexpr auto static_pointer_cast(observer_ptr<U> && other) noexcept -> observer_ptr<T>
+ {
+ return observer_ptr{static_cast<observer_ptr<T>::element_type *>(std::move(other).get())};
+ }
+
+ template<typename T, typename U>
+ [[nodiscard]] constexpr auto dynamic_pointer_cast(observer_ptr<U> const & other) noexcept -> observer_ptr<T> = delete;
+
+ template<typename T, typename U>
+ [[nodiscard]] constexpr auto dynamic_pointer_cast(observer_ptr<U> && other) noexcept -> observer_ptr<T> = delete;
+
+ template<typename T, typename U>
+ [[nodiscard]] constexpr auto const_pointer_cast(observer_ptr<U> const & other) noexcept -> observer_ptr<T>
+ {
+ return observer_ptr{const_cast<observer_ptr<T>::element_type *>(other.get())};
+ }
+
+ template<typename T, typename U>
+ [[nodiscard]] constexpr auto const_pointer_cast(observer_ptr<U> && other) noexcept -> observer_ptr<T>
+ {
+ return observer_ptr{const_cast<observer_ptr<T>::element_type *>(other.get())};
+ }
+
+ template<typename T, typename U>
+ [[nodiscard]] constexpr auto reinterpret_pointer_cast(observer_ptr<U> const & other) noexcept -> observer_ptr<T>
+ {
+ return observer_ptr{reinterpret_cast<observer_ptr<T>::element_type *>(other.get())};
+ }
+
+ template<typename T, typename U>
+ [[nodiscard]] constexpr auto reinterpret_pointer_cast(observer_ptr<U> && other) noexcept -> observer_ptr<T>
+ {
+ return observer_ptr{reinterpret_cast<observer_ptr<T>::element_type *>(other.get())};
+ }
+
} // namespace kstd
#endif \ No newline at end of file