From: Arthur O'Dwyer Date: Tue, 4 Oct 2016 17:24:45 +0000 (-0700) Subject: hazptr: Replace friend "swap" with a member function and a non-friend X-Git-Tag: v2016.10.10.00~19 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=4d012b253803f49ce475d26590878c057291fb43;p=folly.git hazptr: Replace friend "swap" with a member function and a non-friend 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 --- diff --git a/folly/experimental/hazptr/hazptr-impl.h b/folly/experimental/hazptr/hazptr-impl.h index 2c64e9c5..e774d9fb 100644 --- a/folly/experimental/hazptr/hazptr-impl.h +++ b/folly/experimental/hazptr/hazptr-impl.h @@ -123,12 +123,17 @@ inline void hazptr_owner::clear() const noexcept { } template -inline void swap(hazptr_owner& lhs, hazptr_owner& rhs) noexcept { +inline void hazptr_owner::swap(hazptr_owner& 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 +inline void swap(hazptr_owner& lhs, hazptr_owner& rhs) noexcept { + lhs.swap(rhs); } //////////////////////////////////////////////////////////////////////////////// diff --git a/folly/experimental/hazptr/hazptr.h b/folly/experimental/hazptr/hazptr.h index 329dbe64..8353965b 100644 --- a/folly/experimental/hazptr/hazptr.h +++ b/folly/experimental/hazptr/hazptr.h @@ -146,8 +146,9 @@ template class hazptr_owner { /* Clear the hazard pointer */ void clear() const noexcept; + void swap(hazptr_owner&) noexcept; + private: - friend void swap(hazptr_owner&, hazptr_owner&) noexcept; hazptr_domain* domain_; hazptr_rec* hazptr_;