From: Andy H. <and...@gm...> - 2015-05-13 22:14:04
|
This proposal looks good to me. -- Andy On Fri, May 8, 2015 at 4:40 PM, Markus Scherer <mar...@gm...> wrote: > (Take 3, sorry about the old addresses on cc...) > > On Fri, May 8, 2015 at 4:30 PM, Markus Scherer <mar...@gm...> > wrote: > >> Dear ICU team & users, >> >> I would like to propose the following API for: *ICU 56* >> Please provide feedback by: *Tuesday, 2015-05-19* >> Designated API reviewer: *Andy* >> Ticket: http://bugs.icu-project.org/trac/ticket/8324 >> and http://bugs.icu-project.org/trac/ticket/10086 >> >> I would like to propose for LocalPointer, LocalArray, UnicodeString: >> - C++11 move constructor & move assignment operator, >> #ifdef'ed contingent on compiler support, >> and with semantics matching those documented for similar STL classes >> (especially unique_ptr and string) >> - moveFrom() which implements the move assignment but does not require >> C++11 >> - member and non-member swap >> >> In a future proposal I might add these to Formattable and Locale as well. >> >> Also adding to LocalArray a constructor which takes a UErrorCode, and >> adoptInsteadAndCheckErrorCode(), which I seem to have forgotten in ICU 55 >> http://bugs.icu-project.org/trac/ticket/11339 (there does not seem to be >> a good reason not to have these for arrays). >> >> I am adding @internal macros into platform.h for detecting the C++ >> version and whether rvalue references (for move) and noexcept are available. >> >> *localpointer.h* >> >> /** >> * Move constructor, leaves src with isNull(). >> * @param src source smart pointer >> * @draft ICU 56 >> */ >> LocalPointer(LocalPointer<T> &&src) U_NOEXCEPT >> >> /** >> * 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 >> * @draft ICU 56 >> */ >> LocalPointer<T> &operator=(LocalPointer<T> &&src) U_NOEXCEPT >> /** >> * 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 >> /** >> * Swap pointers. >> * @param other other smart pointer >> * @draft ICU 56 >> */ >> void swap(LocalPointer<T> &other) U_NOEXCEPT >> >> /** >> * 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 >> >> /** >> * Constructor takes ownership and reports an error if NULL. >> * >> * This constructor is intended to be used with other-class >> constructors >> * that may report a failure UErrorCode, >> * so that callers need to check only for U_FAILURE(errorCode) >> * and not also separately for isNull(). >> * >> * @param p simple pointer to an array of T objects that is adopted >> * @param errorCode in/out UErrorCode, set to >> U_MEMORY_ALLOCATION_ERROR >> * if p==NULL and no other failure code had been set >> * @draft ICU 56 >> */ >> LocalArray(T *p, UErrorCode &errorCode) >> /** >> * Move constructor, leaves src with isNull(). >> * @param src source smart pointer >> * @draft ICU 56 >> */ >> LocalArray(LocalArray<T> &&src) U_NOEXCEPT >> >> /** >> * 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 >> * @draft ICU 56 >> */ >> LocalArray<T> &operator=(LocalArray<T> &&src) U_NOEXCEPT >> /** >> * 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 >> /** >> * Swap pointers. >> * @param other other smart pointer >> * @draft ICU 56 >> */ >> void swap(LocalArray<T> &other) U_NOEXCEPT >> >> /** >> * Deletes the array it owns, >> * and adopts (takes ownership of) the one passed in. >> * >> * If U_FAILURE(errorCode), then the current array is retained and >> the new one deleted. >> * >> * If U_SUCCESS(errorCode) but the input pointer is NULL, >> * then U_MEMORY_ALLOCATION_ERROR is set, >> * the current array is deleted, and NULL is set. >> * >> * @param p simple pointer to an array of T objects that is adopted >> * @param errorCode in/out UErrorCode, set to >> U_MEMORY_ALLOCATION_ERROR >> * if p==NULL and no other failure code had been set >> * @draft ICU 56 >> */ >> void adoptInsteadAndCheckErrorCode(T *p, UErrorCode &errorCode) >> >> /** >> * 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 >> >> *unistr.h* >> >> /** >> * Move assignment operator, 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. >> * @param src source string >> * @return *this >> * @draft ICU 56 >> */ >> UnicodeString &operator=(UnicodeString &&src) U_NOEXCEPT >> /** >> * 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; >> >> /** >> * Swap strings. >> * @param other other string >> * @draft ICU 56 >> */ >> void swap(UnicodeString &other) U_NOEXCEPT; >> >> /** >> * Move constructor, might leave src in bogus state. >> * This string will have the same contents and state that the source >> string had. >> * @param src source string >> * @draft ICU 56 >> */ >> UnicodeString(UnicodeString &&src) 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 >> */ >> U_COMMON_API inline void U_EXPORT2 >> swap(UnicodeString &s1, UnicodeString &s2) U_NOEXCEPT >> >> Sincerely, >> markus >> > > > > ------------------------------------------------------------------------------ > One dashboard for servers and applications across Physical-Virtual-Cloud > Widest out-of-the-box monitoring support with 50+ applications > Performance metrics, stats and reports that give you Actionable Insights > Deep dive visibility with transaction tracing using APM Insight. > http://ad.doubleclick.net/ddm/clk/290420510;117567292;y > _______________________________________________ > icu-design mailing list > icu...@li... > To Un/Subscribe: https://lists.sourceforge.net/lists/listinfo/icu-design > |