hazptr: Replace friend "swap" with a member function and a non-friend
authorArthur O'Dwyer <arthur.j.odwyer@gmail.com>
Tue, 4 Oct 2016 17:24:45 +0000 (10:24 -0700)
committerFacebook Github Bot <facebook-github-bot-bot@fb.com>
Tue, 4 Oct 2016 17:38:34 +0000 (10:38 -0700)
Summary:
This matches what the STL does with e.g. std::vector::swap() and std::shared_ptr::swap().

http://en.cppreference.com/w/cpp/container/vector/swap
http://en.cppreference.com/w/cpp/memory/shared_ptr/swap

Should be relatively uncontroversial, I would think.
Closes https://github.com/facebook/folly/pull/489

Reviewed By: magedm

Differential Revision: D3963285

Pulled By: yfeldblum

fbshipit-source-id: 3fa6bf77e66fa9a673cb648b0bf87b1db3caa6c8

folly/experimental/hazptr/hazptr-impl.h
folly/experimental/hazptr/hazptr.h

index 2c64e9c5e471f5a5cd113748e0a364d6447e6d43..e774d9fb9695fd4cb80626c798424bf2b0d4bbff 100644 (file)
@@ -123,12 +123,17 @@ inline void hazptr_owner<T>::clear() const noexcept {
 }
 
 template <typename T>
-inline void swap(hazptr_owner<T>& lhs, hazptr_owner<T>& rhs) noexcept {
+inline void hazptr_owner<T>::swap(hazptr_owner<T>& rhs) noexcept {
   DEBUG_PRINT(
-    &lhs << " " <<  lhs.hazptr_ << " " << lhs.domain_ << " -- "
+    this << " " <<  this->hazptr_ << " " << this->domain_ << " -- "
     << &rhs << " " << rhs.hazptr_ << " " << rhs.domain_);
-  std::swap(lhs.domain_, rhs.domain_);
-  std::swap(lhs.hazptr_, rhs.hazptr_);
+  std::swap(this->domain_, rhs.domain_);
+  std::swap(this->hazptr_, rhs.hazptr_);
+}
+
+template <typename T>
+inline void swap(hazptr_owner<T>& lhs, hazptr_owner<T>& rhs) noexcept {
+  lhs.swap(rhs);
 }
 
 ////////////////////////////////////////////////////////////////////////////////
index 329dbe640df3e9bc70746397f269535878dedb58..8353965b9437017c07b5c8de88d5c1c7fb525f0d 100644 (file)
@@ -146,8 +146,9 @@ template <typename T> class hazptr_owner {
   /* Clear the hazard pointer */
   void clear() const noexcept;
 
+  void swap(hazptr_owner&) noexcept;
+
  private:
-  friend void swap<T>(hazptr_owner&, hazptr_owner&) noexcept;
 
   hazptr_domain* domain_;
   hazptr_rec* hazptr_;