diff options
| author | Lukas Oesch <lukasoesch20@gmail.com> | 2026-03-24 19:06:50 +0100 |
|---|---|---|
| committer | Lukas Oesch <lukasoesch20@gmail.com> | 2026-03-26 21:19:04 +0100 |
| commit | 2eb086d516f20a0b5cef9881a3459adb389c6ee8 (patch) | |
| tree | 44b779f4157945b7761b70ee65bc6482afd2c044 /libs/kstd | |
| parent | 7351349f296f100f10db62b5a834a971fbe51473 (diff) | |
| download | teachos-2eb086d516f20a0b5cef9881a3459adb389c6ee8.tar.xz teachos-2eb086d516f20a0b5cef9881a3459adb389c6ee8.zip | |
implement == and <=> operator in shared_ptr
Diffstat (limited to 'libs/kstd')
| -rw-r--r-- | libs/kstd/include/kstd/bits/shared_ptr.hpp | 29 |
1 files changed, 24 insertions, 5 deletions
diff --git a/libs/kstd/include/kstd/bits/shared_ptr.hpp b/libs/kstd/include/kstd/bits/shared_ptr.hpp index 674807d..8930095 100644 --- a/libs/kstd/include/kstd/bits/shared_ptr.hpp +++ b/libs/kstd/include/kstd/bits/shared_ptr.hpp @@ -546,11 +546,6 @@ namespace kstd return ptr.pointer == nullptr; } - /** - * @brief Defaulted three-way comparator operator. - */ - [[nodiscard]] auto operator<=>(shared_ptr const & other) const = default; - private: /** * @brief If the candidate type inherits from enable_shared_from_this, assigns the internal weak pointer to this @@ -624,6 +619,30 @@ namespace kstd { return shared_ptr<T>(new T(std::forward<Args>(args)...)); } + + /** + * @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. + * @param lhs, rhs The shared_ptr instances to compare. + * @return true if lhs and rhs point to the same object, false otherwise. + */ + template<typename T, typename U> + [[nodiscard]] auto inline operator==(shared_ptr<T> const & lhs, shared_ptr<U> const & rhs) -> bool + { + return lhs.get() == rhs.get(); + } + + /** + * @brief Three-way comparison operator for shared_ptr. Compares the stored pointers of lhs and rhs using operator<=>. + * @tparam T, U Types of the managed objects of the shared_ptr instances being compared. + * @param lhs, rhs The shared_ptr instances to compare. + * @return The result of comparing the stored pointers of lhs and rhs using operator<=> + */ + template<typename T, typename U> + [[nodiscard]] auto inline operator<=>(shared_ptr<T> const & lhs, shared_ptr<U> const & rhs) + { + return lhs.get() <=> rhs.get(); + } } // namespace kstd #endif
\ No newline at end of file |
