Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(494)

Unified Diff: source/common/cmemory.h

Issue 1621843002: ICU 56 update step 1 (Closed) Base URL: https://chromium.googlesource.com/chromium/deps/icu.git@561
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « source/common/charstr.cpp ('k') | source/common/common.vcxproj » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: source/common/cmemory.h
diff --git a/source/common/cmemory.h b/source/common/cmemory.h
index d182b5aa7d166930069d52423c7a373e72ceb525..3041b56d1a14010dded80daa7bcf8827121491d0 100644
--- a/source/common/cmemory.h
+++ b/source/common/cmemory.h
@@ -158,12 +158,63 @@ public:
* @param p simple pointer to an array of T items that is adopted
*/
explicit LocalMemory(T *p=NULL) : LocalPointerBase<T>(p) {}
+#if U_HAVE_RVALUE_REFERENCES
+ /**
+ * Move constructor, leaves src with isNull().
+ * @param src source smart pointer
+ */
+ LocalMemory(LocalMemory<T> &&src) U_NOEXCEPT : LocalPointerBase<T>(src.ptr) {
+ src.ptr=NULL;
+ }
+#endif
/**
* Destructor deletes the memory it owns.
*/
~LocalMemory() {
uprv_free(LocalPointerBase<T>::ptr);
}
+#if U_HAVE_RVALUE_REFERENCES
+ /**
+ * Move assignment operator, leaves src with isNull().
+ * The behavior is undefined if *this and src are the same object.
+ * @param src source smart pointer
+ * @return *this
+ */
+ LocalMemory<T> &operator=(LocalMemory<T> &&src) U_NOEXCEPT {
+ return moveFrom(src);
+ }
+#endif
+ /**
+ * Move assignment, leaves src with isNull().
+ * The behavior is undefined if *this and src are the same object.
+ *
+ * Can be called explicitly, does not need C++11 support.
+ * @param src source smart pointer
+ * @return *this
+ */
+ LocalMemory<T> &moveFrom(LocalMemory<T> &src) U_NOEXCEPT {
+ delete[] LocalPointerBase<T>::ptr;
+ LocalPointerBase<T>::ptr=src.ptr;
+ src.ptr=NULL;
+ return *this;
+ }
+ /**
+ * Swap pointers.
+ * @param other other smart pointer
+ */
+ void swap(LocalMemory<T> &other) U_NOEXCEPT {
+ T *temp=LocalPointerBase<T>::ptr;
+ LocalPointerBase<T>::ptr=other.ptr;
+ other.ptr=temp;
+ }
+ /**
+ * Non-member LocalMemory swap function.
+ * @param p1 will get p2's pointer
+ * @param p2 will get p1's pointer
+ */
+ friend inline void swap(LocalMemory<T> &p1, LocalMemory<T> &p2) U_NOEXCEPT {
+ p1.swap(p2);
+ }
/**
* Deletes the array it owns,
* and adopts (takes ownership of) the one passed in.
« no previous file with comments | « source/common/charstr.cpp ('k') | source/common/common.vcxproj » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698