commit | 7cc37bbab7f613e7e5f166ce9cb160284ee95956 | [log] [tgz] |
---|---|---|
author | Mathieu Chartier <mathieuc@google.com> | Fri Nov 09 15:45:15 2012 -0800 |
committer | Brian Carlstrom <bdc@google.com> | Fri May 10 16:52:38 2013 -0700 |
tree | 4544b7cda0a08518ff804ffdd6ad12178a73c43f | |
parent | 9577926537ea6668ec4ade67d5758f871e9e5fb3 [diff] [blame] |
Add swap operation to UniquePtr. Enables swapping without mPtr ever becoming null. Required by https://googleplex-android-review.googlesource.com/#/c/250540/ (cherry picked from commit be7922da0cf9b759f01f09b5f259e083f8d1f0b8) Change-Id: I06ec54e174d251cd2938efba8e628d0eaf6ebcc5
diff --git a/include/nativehelper/UniquePtr.h b/include/nativehelper/UniquePtr.h index 31db377..e27e941 100644 --- a/include/nativehelper/UniquePtr.h +++ b/include/nativehelper/UniquePtr.h
@@ -17,6 +17,7 @@ #ifndef UNIQUE_PTR_H_included #define UNIQUE_PTR_H_included +#include <algorithm> // For std::swap #include <cstdlib> // For NULL. // Default deleter for pointer types. @@ -80,6 +81,11 @@ } } + // Swap with another unique pointer. + void swap(UniquePtr<T>& other) { + std::swap(mPtr, other.mPtr); + } + private: // The raw pointer. T* mPtr;