* @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;
*******************************************************************************
*/
+#include <utility>
+
#include "unicode/utypes.h"
#if !UCONFIG_NO_BREAK_ITERATION
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();
* @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.
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
* @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.
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
: 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; \
* @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.
}
UnicodeString::UnicodeString(UnicodeString &&src) U_NOEXCEPT {
- fUnion.fFields.fLengthAndFlags = kShortString;
- moveFrom(src);
+ copyFieldsFrom(src, TRUE);
}
UnicodeString::UnicodeString(const UnicodeString& that,
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();
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) {
**********************************************************************
*/
+#include <utility>
+
#include "unicode/utypes.h"
#if !UCONFIG_NO_TRANSLITERATION && !UCONFIG_NO_BREAK_ITERATION
{
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));
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);
}
}
* 10/12/05 emmons Added setters for eraNames, month/day by width/context
*******************************************************************************
*/
+
+#include <utility>
+
#include "unicode/utypes.h"
#if !UCONFIG_NO_FORMATTING
// Set the resources to visit on the next calendar
if (!resourcesToVisitNext.isNull()) {
- resourcesToVisit.moveFrom(resourcesToVisitNext);
+ resourcesToVisit = std::move(resourcesToVisitNext);
}
}
// © 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
EraRules::EraRules(LocalMemory<int32_t>& eraStartDates, int32_t numEras)
: numEras(numEras) {
- startDates.moveFrom(eraStartDates);
+ startDates = std::move(eraStartDates);
initCurrentEra();
}
* others. All Rights Reserved.
********************************************************************/
+#include <utility>
/**
* IntlTestUtilities is the medium level test class for everything in the directory "utility".
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);
// 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() {
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);
// 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() {
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);
// 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 */
}
* others. All Rights Reserved.
********************************************************************/
+#include <utility>
+
#include "ustrtest.h"
#include "unicode/appendable.h"
#include "unicode/std_string.h"
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);
// 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;