From 20252755bd9352e0df81e16285ec8ba63299102c Mon Sep 17 00:00:00 2001 From: Chong Kai Xiong Date: Thu, 26 Jan 2023 03:03:04 +0800 Subject: [PATCH] Core (LV::IntrusivePtr): Implement swap() overload as a friend function to work with ADL. Overloading std::swap() is considered UB! --- libvisual/libvisual/lv_intrusive_ptr.hpp | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/libvisual/libvisual/lv_intrusive_ptr.hpp b/libvisual/libvisual/lv_intrusive_ptr.hpp index 72b35191e..9f3543638 100644 --- a/libvisual/libvisual/lv_intrusive_ptr.hpp +++ b/libvisual/libvisual/lv_intrusive_ptr.hpp @@ -135,6 +135,12 @@ namespace LV rhs.m_ptr = tmp; } + //! Swaps two intrusive pointers. + friend void swap (LV::IntrusivePtr& lhs, LV::IntrusivePtr& rhs) + { + lhs.swap (rhs); + } + private: T* m_ptr; @@ -142,15 +148,4 @@ namespace LV } // LV namespace -namespace std { - - // std::swap() overload for efficiently swapping IntrusivePtrs - template - void swap (LV::IntrusivePtr& lhs, LV::IntrusivePtr& rhs) - { - lhs.swap (rhs); - } - -} // std namespace - #endif // _LV_INTRUSIVE_HPP