aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/lib/gprpp/ref_counted_ptr.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/lib/gprpp/ref_counted_ptr.h')
-rw-r--r--src/core/lib/gprpp/ref_counted_ptr.h28
1 files changed, 16 insertions, 12 deletions
diff --git a/src/core/lib/gprpp/ref_counted_ptr.h b/src/core/lib/gprpp/ref_counted_ptr.h
index 91ca8eae63..c2dfbdd90f 100644
--- a/src/core/lib/gprpp/ref_counted_ptr.h
+++ b/src/core/lib/gprpp/ref_counted_ptr.h
@@ -41,21 +41,23 @@ class RefCountedPtr {
value_ = value;
}
- // Move support.
+ // Move ctors.
RefCountedPtr(RefCountedPtr&& other) {
value_ = other.value_;
other.value_ = nullptr;
}
- RefCountedPtr& operator=(RefCountedPtr&& other) {
- if (value_ != nullptr) value_->Unref();
+ template <typename Y>
+ RefCountedPtr(RefCountedPtr<Y>&& other) {
value_ = other.value_;
other.value_ = nullptr;
- return *this;
}
- template <typename Y>
- RefCountedPtr(RefCountedPtr<Y>&& other) {
+
+ // Move assignment.
+ RefCountedPtr& operator=(RefCountedPtr&& other) {
+ if (value_ != nullptr) value_->Unref();
value_ = other.value_;
other.value_ = nullptr;
+ return *this;
}
template <typename Y>
RefCountedPtr& operator=(RefCountedPtr<Y>&& other) {
@@ -65,11 +67,18 @@ class RefCountedPtr {
return *this;
}
- // Copy support.
+ // Copy ctors.
RefCountedPtr(const RefCountedPtr& other) {
if (other.value_ != nullptr) other.value_->IncrementRefCount();
value_ = other.value_;
}
+ template <typename Y>
+ RefCountedPtr(const RefCountedPtr<Y>& other) {
+ if (other.value_ != nullptr) other.value_->IncrementRefCount();
+ value_ = other.value_;
+ }
+
+ // Copy assignment.
RefCountedPtr& operator=(const RefCountedPtr& other) {
// Note: Order of reffing and unreffing is important here in case value_
// and other.value_ are the same object.
@@ -79,11 +88,6 @@ class RefCountedPtr {
return *this;
}
template <typename Y>
- RefCountedPtr(const RefCountedPtr<Y>& other) {
- if (other.value_ != nullptr) other.value_->IncrementRefCount();
- value_ = other.value_;
- }
- template <typename Y>
RefCountedPtr& operator=(const RefCountedPtr<Y>& other) {
// Note: Order of reffing and unreffing is important here in case value_
// and other.value_ are the same object.