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.
T &operator[](ptrdiff_t i) const { return LocalPointerBase<T>::ptr[i]; }
};
-/**
- * Non-member LocalMemory swap function.
- * @param p1 will get p2's pointer
- * @param p2 will get p1's pointer
- */
-template<typename T>
-inline void swap(LocalMemory<T> &p1, LocalMemory<T> &p2) U_NOEXCEPT {
- p1.swap(p2);
-}
-
template<typename T>
inline T *LocalMemory<T>::allocateInsteadAndReset(int32_t newCapacity) {
if(newCapacity>0) {
LocalPointerBase<T>::ptr=other.ptr;
other.ptr=temp;
}
+ /**
+ * Non-member LocalPointer swap function.
+ * @param p1 will get p2's pointer
+ * @param p2 will get p1's pointer
+ * @draft ICU 56
+ */
+ friend inline void swap(LocalPointer<T> &p1, LocalPointer<T> &p2) U_NOEXCEPT {
+ p1.swap(p2);
+ }
#endif /* U_HIDE_DRAFT_API */
/**
* Deletes the object it owns,
#endif /* U_HIDE_DRAFT_API */
};
-#ifndef U_HIDE_DRAFT_API
-/**
- * Non-member LocalPointer swap function.
- * @param p1 will get p2's pointer
- * @param p2 will get p1's pointer
- * @draft ICU 56
- */
-template<typename T>
-inline void swap(LocalPointer<T> &p1, LocalPointer<T> &p2) U_NOEXCEPT {
- p1.swap(p2);
-}
-#endif /* U_HIDE_DRAFT_API */
-
/**
* "Smart pointer" class, deletes objects via the C++ array delete[] operator.
* For most methods see the LocalPointerBase base class.
LocalPointerBase<T>::ptr=other.ptr;
other.ptr=temp;
}
+ /**
+ * Non-member LocalArray swap function.
+ * @param p1 will get p2's pointer
+ * @param p2 will get p1's pointer
+ * @draft ICU 56
+ */
+ friend inline void swap(LocalArray<T> &p1, LocalArray<T> &p2) U_NOEXCEPT {
+ p1.swap(p2);
+ }
#endif /* U_HIDE_DRAFT_API */
/**
* Deletes the array it owns,
T &operator[](ptrdiff_t i) const { return LocalPointerBase<T>::ptr[i]; }
};
-#ifndef U_HIDE_DRAFT_API
-/**
- * Non-member LocalArray swap function.
- * @param p1 will get p2's pointer
- * @param p2 will get p1's pointer
- * @draft ICU 56
- */
-template<typename T>
-inline void swap(LocalArray<T> &p1, LocalArray<T> &p2) U_NOEXCEPT {
- p1.swap(p2);
-}
-#endif /* U_HIDE_DRAFT_API */
-
/**
* \def U_DEFINE_LOCAL_OPEN_POINTER
* "Smart pointer" definition macro, deletes objects via the closeFunction.
LocalPointerBase<Type>::ptr=other.ptr; \
other.ptr=temp; \
} \
+ friend inline void swap(LocalPointerClassName &p1, LocalPointerClassName &p2) U_NOEXCEPT { \
+ p1.swap(p2); \
+ } \
void adoptInstead(Type *p) { \
closeFunction(ptr); \
ptr=p; \
} \
- }; \
- inline void swap(LocalPointerClassName &p1, LocalPointerClassName &p2) U_NOEXCEPT { \
- p1.swap(p2); \
- } \
- class LocalPointerClassName
+ }
#else
#define U_DEFINE_LOCAL_OPEN_POINTER(LocalPointerClassName, Type, closeFunction) \
class LocalPointerClassName : public LocalPointerBase<Type> { \
LocalPointerBase<Type>::ptr=other.ptr; \
other.ptr=temp; \
} \
+ friend inline void swap(LocalPointerClassName &p1, LocalPointerClassName &p2) U_NOEXCEPT { \
+ p1.swap(p2); \
+ } \
void adoptInstead(Type *p) { \
closeFunction(ptr); \
ptr=p; \
} \
- }; \
- inline void swap(LocalPointerClassName &p1, LocalPointerClassName &p2) U_NOEXCEPT { \
- p1.swap(p2); \
- } \
- class LocalPointerClassName
+ }
#endif
-// The trailing class forward declaration at the end of U_DEFINE_LOCAL_OPEN_POINTER
-// prevents a warning or error from -pedantic compilation
-// due to an extra ';' after the non-member swap function definition.
U_NAMESPACE_END
* @draft ICU 56
*/
void swap(UnicodeString &other) U_NOEXCEPT;
+
+ /**
+ * Non-member UnicodeString swap function.
+ * @param s1 will get s2's contents and state
+ * @param s2 will get s1's contents and state
+ * @draft ICU 56
+ */
+ friend U_COMMON_API inline void U_EXPORT2
+ swap(UnicodeString &s1, UnicodeString &s2) U_NOEXCEPT {
+ s1.swap(s2);
+ }
#endif /* U_HIDE_DRAFT_API */
/**
U_COMMON_API UnicodeString U_EXPORT2
operator+ (const UnicodeString &s1, const UnicodeString &s2);
-#ifndef U_HIDE_DRAFT_API
-/**
- * Non-member UnicodeString swap function.
- * @param s1 will get s2's contents and state
- * @param s2 will get s1's contents and state
- * @draft ICU 56
- */
-U_COMMON_API inline void U_EXPORT2
-swap(UnicodeString &s1, UnicodeString &s2) U_NOEXCEPT {
- s1.swap(s2);
-}
-#endif /* U_HIDE_DRAFT_API */
-
//========================================
// Inline members
//========================================
int16_t lengthAndFlags = fUnion.fFields.fLengthAndFlags = src.fUnion.fFields.fLengthAndFlags;
if(lengthAndFlags & kUsingStackBuffer) {
// Short string using the stack buffer, copy the contents.
- uprv_memcpy(fUnion.fStackFields.fBuffer, src.fUnion.fStackFields.fBuffer,
- getShortLength() * U_SIZEOF_UCHAR);
+ // Check for self assignment to prevent "overlap in memcpy" warnings,
+ // although it should be harmless to copy a buffer to itself exactly.
+ if(this != &src) {
+ uprv_memcpy(fUnion.fStackFields.fBuffer, src.fUnion.fStackFields.fBuffer,
+ getShortLength() * U_SIZEOF_UCHAR);
+ }
} else {
// In all other cases, copy all fields.
fUnion.fFields.fArray = src.fUnion.fFields.fArray;