diff options
author | Ivan Solovev <ivan.solovev@qt.io> | 2021-01-20 11:42:14 +0100 |
---|---|---|
committer | Ivan Solovev <ivan.solovev@qt.io> | 2021-01-26 17:20:01 +0100 |
commit | fe7cbf8fe671cfe7a39ddaf8a963f9e7e3cd79ef (patch) | |
tree | a584e0f9c30c3facb300dddc0785a7cf2e40913d /src/corelib | |
parent | 114d5c045da872be8cd304949c86b9e9655af2bf (diff) |
QRegularExpression: add move constructor
- Add move constructors to QRegularExpression, QRegularExpressionMatch
and QRegularExpressionMatchIterator.
- Update the documentation to explicitly state that only destructor
and assignment operators can be called for a moved-from object
Task-number: QTBUG-86634
Change-Id: I06b4f54e300541033a9a18339c97338717a06da0
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
Diffstat (limited to 'src/corelib')
-rw-r--r-- | src/corelib/text/qregularexpression.cpp | 73 | ||||
-rw-r--r-- | src/corelib/text/qregularexpression.h | 8 |
2 files changed, 75 insertions, 6 deletions
diff --git a/src/corelib/text/qregularexpression.cpp b/src/corelib/text/qregularexpression.cpp index 1127b77831..72079c1996 100644 --- a/src/corelib/text/qregularexpression.cpp +++ b/src/corelib/text/qregularexpression.cpp @@ -2,7 +2,7 @@ ** ** Copyright (C) 2020 Giuseppe D'Angelo <dangelog@gmail.com>. ** Copyright (C) 2020 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2021 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the QtCore module of the Qt Toolkit. @@ -1371,12 +1371,28 @@ QRegularExpression::QRegularExpression(const QRegularExpression &re) } /*! + \fn QRegularExpression::QRegularExpression(QRegularExpression &&re) + + \since 6.1 + + Constructs a QRegularExpression object by moving from \a re. + + Note that a moved-from QRegularExpression can only be destroyed or + assigned to. The effect of calling other functions than the destructor + or one of the assignment operators is undefined. + + \sa operator=() +*/ + +/*! Destroys the QRegularExpression object. */ QRegularExpression::~QRegularExpression() { } +QT_DEFINE_QESDP_SPECIALIZATION_DTOR(QRegularExpressionPrivate) + /*! Assigns the regular expression \a re to this object, and returns a reference to the copy. Both the pattern and the pattern options are copied. @@ -1723,8 +1739,12 @@ bool QRegularExpression::operator==(const QRegularExpression &re) const /*! \fn QRegularExpression & QRegularExpression::operator=(QRegularExpression && re) - Move-assigns the regular expression \a re to this object, and returns a reference - to the copy. Both the pattern and the pattern options are copied. + Move-assigns the regular expression \a re to this object, and returns a + reference to the result. Both the pattern and the pattern options are copied. + + Note that a moved-from QRegularExpression can only be destroyed or + assigned to. The effect of calling other functions than the destructor + or one of the assignment operators is undefined. */ /*! @@ -2036,6 +2056,8 @@ QRegularExpressionMatch::~QRegularExpressionMatch() { } +QT_DEFINE_QESDP_SPECIALIZATION_DTOR(QRegularExpressionMatchPrivate) + /*! Constructs a match result by copying the result of the given \a match. @@ -2047,6 +2069,20 @@ QRegularExpressionMatch::QRegularExpressionMatch(const QRegularExpressionMatch & } /*! + \fn QRegularExpressionMatch::QRegularExpressionMatch(QRegularExpressionMatch &&match) + + \since 6.1 + + Constructs a match result by moving the result from the given \a match. + + Note that a moved-from QRegularExpressionMatch can only be destroyed or + assigned to. The effect of calling other functions than the destructor + or one of the assignment operators is undefined. + + \sa operator=() +*/ + +/*! Assigns the match result \a match to this object, and returns a reference to the copy. */ @@ -2059,8 +2095,12 @@ QRegularExpressionMatch &QRegularExpressionMatch::operator=(const QRegularExpres /*! \fn QRegularExpressionMatch &QRegularExpressionMatch::operator=(QRegularExpressionMatch &&match) - Move-assigns the match result \a match to this object, and returns a reference - to the copy. + Move-assigns the match result \a match to this object, and returns a + reference to the result. + + Note that a moved-from QRegularExpressionMatch can only be destroyed or + assigned to. The effect of calling other functions than the destructor + or one of the assignment operators is undefined. */ /*! @@ -2468,6 +2508,8 @@ QRegularExpressionMatchIterator::~QRegularExpressionMatchIterator() { } +QT_DEFINE_QESDP_SPECIALIZATION_DTOR(QRegularExpressionMatchIteratorPrivate) + /*! Constructs a QRegularExpressionMatchIterator object as a copy of \a iterator. @@ -2480,6 +2522,20 @@ QRegularExpressionMatchIterator::QRegularExpressionMatchIterator(const QRegularE } /*! + \fn QRegularExpressionMatchIterator::QRegularExpressionMatchIterator(QRegularExpressionMatchIterator &&iterator) + + \since 6.1 + + Constructs a QRegularExpressionMatchIterator object by moving from \a iterator. + + Note that a moved-from QRegularExpressionMatchIterator can only be destroyed + or assigned to. The effect of calling other functions than the destructor + or one of the assignment operators is undefined. + + \sa operator=() +*/ + +/*! Assigns the iterator \a iterator to this object, and returns a reference to the copy. */ @@ -2492,7 +2548,12 @@ QRegularExpressionMatchIterator &QRegularExpressionMatchIterator::operator=(cons /*! \fn QRegularExpressionMatchIterator &QRegularExpressionMatchIterator::operator=(QRegularExpressionMatchIterator &&iterator) - Move-assigns the \a iterator to this object. + Move-assigns the \a iterator to this object, and returns a reference to the + result. + + Note that a moved-from QRegularExpressionMatchIterator can only be destroyed + or assigned to. The effect of calling other functions than the destructor + or one of the assignment operators is undefined. */ /*! diff --git a/src/corelib/text/qregularexpression.h b/src/corelib/text/qregularexpression.h index 142ec7f838..570679800c 100644 --- a/src/corelib/text/qregularexpression.h +++ b/src/corelib/text/qregularexpression.h @@ -2,6 +2,7 @@ ** ** Copyright (C) 2020 Giuseppe D'Angelo <dangelog@gmail.com>. ** Copyright (C) 2020 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> +** Copyright (C) 2021 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the QtCore module of the Qt Toolkit. @@ -60,6 +61,8 @@ class QRegularExpressionMatchIterator; struct QRegularExpressionPrivate; class QRegularExpression; +QT_DECLARE_QESDP_SPECIALIZATION_DTOR_WITH_EXPORT(QRegularExpressionPrivate, Q_CORE_EXPORT) + Q_CORE_EXPORT size_t qHash(const QRegularExpression &key, size_t seed = 0) noexcept; class Q_CORE_EXPORT QRegularExpression @@ -86,6 +89,7 @@ public: QRegularExpression(); explicit QRegularExpression(const QString &pattern, PatternOptions options = NoPatternOption); QRegularExpression(const QRegularExpression &re); + QRegularExpression(QRegularExpression &&re) = default; ~QRegularExpression(); QRegularExpression &operator=(const QRegularExpression &re); QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QRegularExpression) @@ -204,6 +208,7 @@ Q_CORE_EXPORT QDebug operator<<(QDebug debug, QRegularExpression::PatternOptions #endif struct QRegularExpressionMatchPrivate; +QT_DECLARE_QESDP_SPECIALIZATION_DTOR_WITH_EXPORT(QRegularExpressionMatchPrivate, Q_CORE_EXPORT) class Q_CORE_EXPORT QRegularExpressionMatch { @@ -211,6 +216,7 @@ public: QRegularExpressionMatch(); ~QRegularExpressionMatch(); QRegularExpressionMatch(const QRegularExpressionMatch &match); + QRegularExpressionMatch(QRegularExpressionMatch &&match) = default; QRegularExpressionMatch &operator=(const QRegularExpressionMatch &match); QRegularExpressionMatch &operator=(QRegularExpressionMatch &&match) noexcept { d.swap(match.d); return *this; } @@ -278,6 +284,7 @@ class QRegularExpressionMatchIteratorRangeBasedForIteratorSentinel {}; } struct QRegularExpressionMatchIteratorPrivate; +QT_DECLARE_QESDP_SPECIALIZATION_DTOR_WITH_EXPORT(QRegularExpressionMatchIteratorPrivate, Q_CORE_EXPORT) class Q_CORE_EXPORT QRegularExpressionMatchIterator { @@ -285,6 +292,7 @@ public: QRegularExpressionMatchIterator(); ~QRegularExpressionMatchIterator(); QRegularExpressionMatchIterator(const QRegularExpressionMatchIterator &iterator); + QRegularExpressionMatchIterator(QRegularExpressionMatchIterator &&iterator) = default; QRegularExpressionMatchIterator &operator=(const QRegularExpressionMatchIterator &iterator); QRegularExpressionMatchIterator &operator=(QRegularExpressionMatchIterator &&iterator) noexcept { d.swap(iterator.d); return *this; } |