]> granicus.if.org Git - icu/commitdiff
ICU-13081 remove C++ moveFrom() functions: still draft, but obsolete since we require...
authorMarkus Scherer <markus.icu@gmail.com>
Wed, 6 Feb 2019 19:49:34 +0000 (11:49 -0800)
committerMarkus Scherer <markus.icu@gmail.com>
Wed, 6 Feb 2019 21:36:53 +0000 (13:36 -0800)
icu4c/source/common/cmemory.h
icu4c/source/common/dictbe.cpp
icu4c/source/common/unicode/localpointer.h
icu4c/source/common/unicode/unistr.h
icu4c/source/common/unistr.cpp
icu4c/source/i18n/brktrans.cpp
icu4c/source/i18n/dtfmtsym.cpp
icu4c/source/i18n/erarules.cpp
icu4c/source/test/intltest/itutil.cpp
icu4c/source/test/intltest/ustrtest.cpp

index ac36d10f7ab4e1c4135f1331ec2740bdfbf9b129..5c48547a5e2721d8ea19861b9fd042f2561e2fda 100644 (file)
@@ -165,17 +165,6 @@ public:
      * @return *this
      */
     LocalMemory<T> &operator=(LocalMemory<T> &&src) U_NOEXCEPT {
-        return moveFrom(src);
-    }
-    /**
-     * 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 {
         uprv_free(LocalPointerBase<T>::ptr);
         LocalPointerBase<T>::ptr=src.ptr;
         src.ptr=NULL;
index cdef79386982e99b4c96775ca2109623d3b20f75..0c2612ad3ca6a77e240640d028e399b226da1ff7 100644 (file)
@@ -7,6 +7,8 @@
  *******************************************************************************
  */
 
+#include <utility>
+
 #include "unicode/utypes.h"
 
 #if !UCONFIG_NO_BREAK_ITERATION
@@ -1204,8 +1206,8 @@ CjkBreakEngine::divideUpDictionaryRange( UText *inText,
                 inputMap->elementAti(inString.length()) : inString.length()+rangeStart;
         normalizedMap->addElement(nativeEnd, status);
 
-        inputMap.moveFrom(normalizedMap);
-        inString.moveFrom(normalizedInput);
+        inputMap = std::move(normalizedMap);
+        inString = std::move(normalizedInput);
     }
 
     int32_t numCodePts = inString.countChar32();
index b618be9c974598c48a10394c48d22fa3aa724636..94ed3657fba4fe4666c78bc7fa10d0032d3246ce 100644 (file)
@@ -251,7 +251,10 @@ public:
      * @stable ICU 56
      */
     LocalPointer<T> &operator=(LocalPointer<T> &&src) U_NOEXCEPT {
-        return moveFrom(src);
+        delete LocalPointerBase<T>::ptr;
+        LocalPointerBase<T>::ptr=src.ptr;
+        src.ptr=NULL;
+        return *this;
     }
     /**
      * Move-assign from an std::unique_ptr to this LocalPointer.
@@ -265,22 +268,6 @@ public:
         adoptInstead(p.release());
         return *this;
     }
-    // do not use #ifndef U_HIDE_DRAFT_API for moveFrom, needed by non-draft API
-    /**
-     * 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
-     * @draft ICU 56
-     */
-    LocalPointer<T> &moveFrom(LocalPointer<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
@@ -434,7 +421,10 @@ public:
      * @stable ICU 56
      */
     LocalArray<T> &operator=(LocalArray<T> &&src) U_NOEXCEPT {
-        return moveFrom(src);
+        delete[] LocalPointerBase<T>::ptr;
+        LocalPointerBase<T>::ptr=src.ptr;
+        src.ptr=NULL;
+        return *this;
     }
     /**
      * Move-assign from an std::unique_ptr to this LocalPointer.
@@ -448,22 +438,6 @@ public:
         adoptInstead(p.release());
         return *this;
     }
-    // do not use #ifndef U_HIDE_DRAFT_API for moveFrom, needed by non-draft API
-    /**
-     * 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
-     * @draft ICU 56
-     */
-    LocalArray<T> &moveFrom(LocalArray<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
@@ -578,19 +552,16 @@ public:
                 : LocalPointerBase<Type>(p.release()) {} \
         ~LocalPointerClassName() { if (ptr != NULL) { closeFunction(ptr); } } \
         LocalPointerClassName &operator=(LocalPointerClassName &&src) U_NOEXCEPT { \
-            return moveFrom(src); \
+            if (ptr != NULL) { closeFunction(ptr); } \
+            LocalPointerBase<Type>::ptr=src.ptr; \
+            src.ptr=NULL; \
+            return *this; \
         } \
         /* TODO: Be agnostic of the deleter function signature from the user-provided std::unique_ptr? */ \
         LocalPointerClassName &operator=(std::unique_ptr<Type, decltype(&closeFunction)> &&p) { \
             adoptInstead(p.release()); \
             return *this; \
         } \
-        LocalPointerClassName &moveFrom(LocalPointerClassName &src) U_NOEXCEPT { \
-            if (ptr != NULL) { closeFunction(ptr); } \
-            LocalPointerBase<Type>::ptr=src.ptr; \
-            src.ptr=NULL; \
-            return *this; \
-        } \
         void swap(LocalPointerClassName &other) U_NOEXCEPT { \
             Type *temp=LocalPointerBase<Type>::ptr; \
             LocalPointerBase<Type>::ptr=other.ptr; \
index 8bb7dcae585f8a33f68f9c0bbf2edd27023f0d79..422b22b956b782596fd89bc3d6659ad37d11e55e 100644 (file)
@@ -1900,22 +1900,7 @@ public:
    * @return *this
    * @stable ICU 56
    */
-  UnicodeString &operator=(UnicodeString &&src) U_NOEXCEPT {
-    return moveFrom(src);
-  }
-
-  // do not use #ifndef U_HIDE_DRAFT_API for moveFrom, needed by non-draft API
-  /**
-   * Move assignment; might leave src in bogus state.
-   * This string will have the same contents and state that the source string had.
-   * 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 string
-   * @return *this
-   * @draft ICU 56
-   */
-  UnicodeString &moveFrom(UnicodeString &src) U_NOEXCEPT;
+  UnicodeString &operator=(UnicodeString &&src) U_NOEXCEPT;
 
   /**
    * Swap strings.
index c8b6c0a3a46319219b7e9d15a220dc5930786401..8f065158654e0c8ad69a921df627a9cef1019324 100644 (file)
@@ -309,8 +309,7 @@ UnicodeString::UnicodeString(const UnicodeString& that) {
 }
 
 UnicodeString::UnicodeString(UnicodeString &&src) U_NOEXCEPT {
-  fUnion.fFields.fLengthAndFlags = kShortString;
-  moveFrom(src);
+  copyFieldsFrom(src, TRUE);
 }
 
 UnicodeString::UnicodeString(const UnicodeString& that,
@@ -572,7 +571,7 @@ UnicodeString::copyFrom(const UnicodeString &src, UBool fastCopy) {
   return *this;
 }
 
-UnicodeString &UnicodeString::moveFrom(UnicodeString &src) U_NOEXCEPT {
+UnicodeString &UnicodeString::operator=(UnicodeString &&src) U_NOEXCEPT {
   // No explicit check for self move assignment, consistent with standard library.
   // Self move assignment causes no crash nor leak but might make the object bogus.
   releaseArray();
@@ -580,7 +579,7 @@ UnicodeString &UnicodeString::moveFrom(UnicodeString &src) U_NOEXCEPT {
   return *this;
 }
 
-// Same as moveFrom() except without memory management.
+// Same as move assignment except without memory management.
 void UnicodeString::copyFieldsFrom(UnicodeString &src, UBool setSrcToBogus) U_NOEXCEPT {
   int16_t lengthAndFlags = fUnion.fFields.fLengthAndFlags = src.fUnion.fFields.fLengthAndFlags;
   if(lengthAndFlags & kUsingStackBuffer) {
index ab5a8038420b78ccd0b851cef7eed69373443b37..ac9e2afb7e4679f9de799d20c8265a5b347fb155 100644 (file)
@@ -10,6 +10,8 @@
 **********************************************************************
 */
 
+#include <utility>
+
 #include "unicode/utypes.h"
 
 #if  !UCONFIG_NO_TRANSLITERATION && !UCONFIG_NO_BREAK_ITERATION
@@ -79,8 +81,8 @@ void BreakTransliterator::handleTransliterate(Replaceable& text, UTransPosition&
         {
             Mutex m;
             BreakTransliterator *nonConstThis = const_cast<BreakTransliterator *>(this);
-            boundaries.moveFrom(nonConstThis->cachedBoundaries);
-            bi.moveFrom(nonConstThis->cachedBI);
+            boundaries = std::move(nonConstThis->cachedBoundaries);
+            bi = std::move(nonConstThis->cachedBI);
         }
         if (bi.isNull()) {
             bi.adoptInstead(BreakIterator::createWordInstance(Locale::getEnglish(), status));
@@ -145,10 +147,10 @@ void BreakTransliterator::handleTransliterate(Replaceable& text, UTransPosition&
             Mutex m;
             BreakTransliterator *nonConstThis = const_cast<BreakTransliterator *>(this);
             if (nonConstThis->cachedBI.isNull()) {
-                nonConstThis->cachedBI.moveFrom(bi);
+                nonConstThis->cachedBI = std::move(bi);
             }
             if (nonConstThis->cachedBoundaries.isNull()) {
-                nonConstThis->cachedBoundaries.moveFrom(boundaries);
+                nonConstThis->cachedBoundaries = std::move(boundaries);
             }
         }
 
index aba37600887f522c1151981c076ed53169ad6902..ae7d2928ae3429b498464aa5ccf79153138ae7df 100644 (file)
@@ -21,6 +21,9 @@
 *   10/12/05    emmons      Added setters for eraNames, month/day by width/context
 *******************************************************************************
 */
+
+#include <utility>
+
 #include "unicode/utypes.h"
 
 #if !UCONFIG_NO_FORMATTING
@@ -1663,7 +1666,7 @@ struct CalendarDataSink : public ResourceSink {
 
         // Set the resources to visit on the next calendar
         if (!resourcesToVisitNext.isNull()) {
-            resourcesToVisit.moveFrom(resourcesToVisitNext);
+            resourcesToVisit = std::move(resourcesToVisitNext);
         }
     }
 
index f6cbc25946300bbba292396d93df0ba75dba2ffa..7249601d64b3ac8e8d8e21312c8a79c5d6d5c35a 100644 (file)
@@ -1,6 +1,8 @@
 // © 2018 and later: Unicode, Inc. and others.
 // License & terms of use: http://www.unicode.org/copyright.html
 
+#include <utility>
+
 #include "unicode/utypes.h"
 
 #if !UCONFIG_NO_FORMATTING
@@ -101,7 +103,7 @@ static int32_t compareEncodedDateWithYMD(int encoded, int year, int month, int d
 
 EraRules::EraRules(LocalMemory<int32_t>& eraStartDates, int32_t numEras)
     : numEras(numEras) {
-    startDates.moveFrom(eraStartDates);
+    startDates = std::move(eraStartDates);
     initCurrentEra();
 }
 
index 2edca05df75014ee980455145ac504194c3c2e5c..a8b6001839edd8ddc8780837274f266bd7730623 100644 (file)
@@ -6,6 +6,7 @@
  * others. All Rights Reserved.
  ********************************************************************/
 
+#include <utility>
 
 /**
  * IntlTestUtilities is the medium level test class for everything in the directory "utility".
@@ -499,9 +500,9 @@ void LocalPointerTest::TestLocalPointerMoveSwap() {
         errln("swap(LocalPointer) did not swap back");
     }
     LocalPointer<UnicodeString> s3;
-    s3.moveFrom(s1);
+    s3 = std::move(s1);
     if(s3.getAlias() != p1 || s1.isValid()) {
-        errln("LocalPointer.moveFrom() did not move");
+        errln("LocalPointer = std::move() did not move");
     }
     infoln("TestLocalPointerMoveSwap() with rvalue references");
     s1 = static_cast<LocalPointer<UnicodeString> &&>(s3);
@@ -516,8 +517,8 @@ void LocalPointerTest::TestLocalPointerMoveSwap() {
     // Move self assignment leaves the object valid but in an undefined state.
     // Do it to make sure there is no crash,
     // but do not check for any particular resulting value.
-    s1.moveFrom(s1);
-    s3.moveFrom(s3);
+    s1 = std::move(s1);
+    s3 = std::move(s3);
 }
 
 void LocalPointerTest::TestLocalPointerStdUniquePtr() {
@@ -605,9 +606,9 @@ void LocalPointerTest::TestLocalArrayMoveSwap() {
         errln("swap(LocalArray) did not swap back");
     }
     LocalArray<UnicodeString> a3;
-    a3.moveFrom(a1);
+    a3 = std::move(a1);
     if(a3.getAlias() != p1 || a1.isValid()) {
-        errln("LocalArray.moveFrom() did not move");
+        errln("LocalArray = std::move() did not move");
     }
     infoln("TestLocalArrayMoveSwap() with rvalue references");
     a1 = static_cast<LocalArray<UnicodeString> &&>(a3);
@@ -622,8 +623,8 @@ void LocalPointerTest::TestLocalArrayMoveSwap() {
     // Move self assignment leaves the object valid but in an undefined state.
     // Do it to make sure there is no crash,
     // but do not check for any particular resulting value.
-    a1.moveFrom(a1);
-    a3.moveFrom(a3);
+    a1 = std::move(a1);
+    a3 = std::move(a3);
 }
 
 void LocalPointerTest::TestLocalArrayStdUniquePtr() {
@@ -787,9 +788,9 @@ void LocalPointerTest::TestLocalXyzPointerMoveSwap() {
         errln("swap(LocalUNormalizer2Pointer) did not swap back");
     }
     LocalUNormalizer2Pointer f3;
-    f3.moveFrom(f1);
+    f3 = std::move(f1);
     if(f3.getAlias() != p1 || f1.isValid()) {
-        errln("LocalUNormalizer2Pointer.moveFrom() did not move");
+        errln("LocalUNormalizer2Pointer = std::move() did not move");
     }
     infoln("TestLocalXyzPointerMoveSwap() with rvalue references");
     f1 = static_cast<LocalUNormalizer2Pointer &&>(f3);
@@ -803,8 +804,8 @@ void LocalPointerTest::TestLocalXyzPointerMoveSwap() {
     // Move self assignment leaves the object valid but in an undefined state.
     // Do it to make sure there is no crash,
     // but do not check for any particular resulting value.
-    f1.moveFrom(f1);
-    f3.moveFrom(f3);
+    f1 = std::move(f1);
+    f3 = std::move(f3);
 #endif /* !UCONFIG_NO_NORMALIZATION */
 }
 
index e33926101393acf6102152113124893b50e11d25..30a36322ae9553c5d81e0404b2b54f4595f35f12 100644 (file)
@@ -6,6 +6,8 @@
  * others. All Rights Reserved.
  ********************************************************************/
 
+#include <utility>
+
 #include "ustrtest.h"
 #include "unicode/appendable.h"
 #include "unicode/std_string.h"
@@ -2145,19 +2147,19 @@ UnicodeStringTest::TestMoveSwap() {
         errln("swap(UnicodeString) did not swap back");
     }
     UnicodeString s4;
-    s4.moveFrom(s1);
+    s4 = std::move(s1);
     if(s4.getBuffer() != p || s4.length() != 100 || !s1.isBogus()) {
-        errln("UnicodeString.moveFrom(heap) did not move");
+        errln("UnicodeString = std::move(heap) did not move");
     }
     UnicodeString s5;
-    s5.moveFrom(s2);
+    s5 = std::move(s2);
     if(s5 != UNICODE_STRING_SIMPLE("defg")) {
-        errln("UnicodeString.moveFrom(stack) did not move");
+        errln("UnicodeString = std::move(stack) did not move");
     }
     UnicodeString s6;
-    s6.moveFrom(s3);
+    s6 = std::move(s3);
     if(s6.getBuffer() != abc || s6.length() != 3) {
-        errln("UnicodeString.moveFrom(alias) did not move");
+        errln("UnicodeString = std::move(alias) did not move");
     }
     infoln("TestMoveSwap() with rvalue references");
     s1 = static_cast<UnicodeString &&>(s6);
@@ -2172,13 +2174,13 @@ UnicodeStringTest::TestMoveSwap() {
     // Move self assignment leaves the object valid but in an undefined state.
     // Do it to make sure there is no crash,
     // but do not check for any particular resulting value.
-    s1.moveFrom(s1);
-    s2.moveFrom(s2);
-    s3.moveFrom(s3);
-    s4.moveFrom(s4);
-    s5.moveFrom(s5);
-    s6.moveFrom(s6);
-    s7.moveFrom(s7);
+    s1 = std::move(s1);
+    s2 = std::move(s2);
+    s3 = std::move(s3);
+    s4 = std::move(s4);
+    s5 = std::move(s5);
+    s6 = std::move(s6);
+    s7 = std::move(s7);
     // Simple copy assignment must work.
     UnicodeString simple = UNICODE_STRING_SIMPLE("simple");
     s1 = s6 = s4 = s7 = simple;