From 4f077b7e5ff1081afc0e362bdab6522c2b7ee43b Mon Sep 17 00:00:00 2001 From: Kari Oikarinen Date: Mon, 11 Nov 2019 13:35:53 +0200 Subject: QScopeGuard: Make constructor public With Class Template Argument Deduction users might want to use the constructor itself instead of a separate helper function. In both cases it's possible to let the compiler deduce the template arguments. Try to make the usefulness of the helper function in the absence of CTAD still clear in the documentation. Change-Id: I9b07983c1fb276a6dd9e7ed4c3e606764e9b68ca Reviewed-by: Ville Voutilainen --- src/corelib/tools/qscopeguard.h | 37 +++++++++++++++++++++++----------- src/corelib/tools/qscopeguard.qdoc | 41 ++++++++++++++++++++++++++++---------- 2 files changed, 55 insertions(+), 23 deletions(-) (limited to 'src/corelib/tools') diff --git a/src/corelib/tools/qscopeguard.h b/src/corelib/tools/qscopeguard.h index 40d2747b1d..4d2e715df1 100644 --- a/src/corelib/tools/qscopeguard.h +++ b/src/corelib/tools/qscopeguard.h @@ -1,6 +1,7 @@ /**************************************************************************** ** ** Copyright (C) 2018 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Sérgio Martins +** Copyright (C) 2019 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the QtCore module of the Qt Toolkit. @@ -45,10 +46,6 @@ QT_BEGIN_NAMESPACE - -template class QScopeGuard; -template QScopeGuard qScopeGuard(F f); - template class #if __has_cpp_attribute(nodiscard) @@ -59,13 +56,23 @@ Q_REQUIRED_RESULT QScopeGuard { public: + explicit QScopeGuard(F &&f) noexcept + : m_func(std::move(f)) + { + } + + explicit QScopeGuard(const F &f) noexcept + : m_func(f) + { + } + QScopeGuard(QScopeGuard &&other) noexcept : m_func(std::move(other.m_func)) , m_invoke(qExchange(other.m_invoke, false)) { } - ~QScopeGuard() + ~QScopeGuard() noexcept { if (m_invoke) m_func(); @@ -77,28 +84,34 @@ public: } private: - explicit QScopeGuard(F &&f) noexcept - : m_func(std::move(f)) - { - } - Q_DISABLE_COPY(QScopeGuard) F m_func; bool m_invoke = true; - friend QScopeGuard qScopeGuard(F); }; +#ifdef __cpp_deduction_guides +template QScopeGuard(F(&)()) -> QScopeGuard; +#endif template #if __has_cpp_attribute(nodiscard) Q_REQUIRED_RESULT #endif -QScopeGuard qScopeGuard(F f) +QScopeGuard qScopeGuard(F &&f) { return QScopeGuard(std::move(f)); } +template +#if __has_cpp_attribute(nodiscard) +Q_REQUIRED_RESULT +#endif +QScopeGuard qScopeGuard(const F &f) +{ + return QScopeGuard(f); +} + QT_END_NAMESPACE #endif // QSCOPEGUARD_H diff --git a/src/corelib/tools/qscopeguard.qdoc b/src/corelib/tools/qscopeguard.qdoc index 6b3c942e84..572934d890 100644 --- a/src/corelib/tools/qscopeguard.qdoc +++ b/src/corelib/tools/qscopeguard.qdoc @@ -1,6 +1,7 @@ /**************************************************************************** ** ** Copyright (C) 2018 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Sérgio Martins +** Copyright (C) 2019 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the documentation of the Qt Toolkit. @@ -35,6 +36,30 @@ QT_BEGIN_NAMESPACE \inmodule QtCore \brief Provides a scope guard for calling a function at the end of a scope. + + QScopeGuard is a class of which the sole purpose is to run the function + \a f in its destructor. This is useful for guaranteeing + your cleanup code is executed, whether the function is exited normally, + exited early by a return statement, or exited by an exception. + + \note Exceptions are not supported. The callable shouldn't throw when + executed, copied or moved. + + \sa QScopedValueRollback +*/ + +/*! + \fn template QScopeGuard::QScopeGuard(F &&f) + \fn template QScopeGuard::QScopeGuard(const F &f) + + Create a scope guard that will execute \a f at the end of the scope. + + If \e F is a lambda, its type cannot be written. In that case you need to + either rely on class template argument deduction (C++17 feature) and leave + the template parameter out completely or use the helper function + qScopeGuard() instead of this constructor. + + \since 5.15 */ /*! \fn template void QScopeGuard::dismiss() @@ -51,23 +76,17 @@ QT_BEGIN_NAMESPACE of the scope. \ingroup misc - QScopeGuard is a class of which the sole purpose is to run the function - \a f in its destructor. This is useful for guaranteeing - your cleanup code is executed, whether the function is exited normally, - exited early by a return statement, or exited by an exception. + Create a scope guard that will execute \a f at the end of the scope. - If \e F is a lambda then you cannot instantiate the template directly, - therefore the qScopeGuard() helper is provided and QScopeGuard is made a - private implementation detail. + This helper function is provided so that you can easily construct a + QScopeGuard without having to name the template parameter for the type of + the callable. If \e F is a lambda then you cannot write its type and relying + on this helper or class template argument deduction is necessary. Example usage is as follows: \snippet code/src_corelib_tools_qscopeguard.cpp 0 - \note Exceptions are not supported. The callable shouldn't throw when - executed, copied or moved. - - \sa QScopedValueRollback */ QT_END_NAMESPACE -- cgit v1.2.3 From 22d0e91970b6ac53a51a715e47cae4e4209cd78b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A5rten=20Nordheim?= Date: Tue, 28 Jan 2020 12:55:15 +0100 Subject: QHash: Re-remove Java-style iterator When deprecating reverse iteratation for QHash the macro defining QHashIterator was expanded but QT_NO_JAVA_STYLE_ITERATORS was unfortunately forgotten. This patch brings it back. Amends dbb54805f63f9ed68d84fe090d608872f16170d2 Change-Id: I7b1912a13f6f8d2446c1f61a1c4a19afb2f28993 Reviewed-by: Lars Knoll --- src/corelib/tools/qhash.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/corelib/tools') diff --git a/src/corelib/tools/qhash.h b/src/corelib/tools/qhash.h index 0b8a0b283d..921b781f4a 100644 --- a/src/corelib/tools/qhash.h +++ b/src/corelib/tools/qhash.h @@ -1264,6 +1264,7 @@ Q_OUTOFLINE_TEMPLATE int QMultiHash::count(const Key &akey) const return cnt; } +#if !defined(QT_NO_JAVA_STYLE_ITERATORS) template class QHashIterator { @@ -1438,6 +1439,7 @@ public: } #endif }; +#endif // !QT_NO_JAVA_STYLE_ITERATORS template uint qHash(const QHash &key, uint seed = 0) -- cgit v1.2.3 From 89f443dfbc980313f19cc8c6a205491a41c9926a Mon Sep 17 00:00:00 2001 From: Kari Oikarinen Date: Thu, 30 Jan 2020 12:46:47 +0200 Subject: QScopeGuard: Fix build failures with qScopeGuard() Partially reverts 4f077b7e5ff1081afc0e362bdab6522c2b7ee43b. Can't overload with forwarding references and lvalue references. Use a single forwarding reference overload, but take care of not trying to create a QScopeGuard of reference type and forward instead of moving. Add tests to ensure calling with both lvalues and rvalues is possible. Change-Id: Ia034afe0a8feb08246c2c7c154a85cae37421c98 Reviewed-by: Ville Voutilainen Reviewed-by: Volker Hilsheimer Reviewed-by: Simon Hausmann --- src/corelib/tools/qscopeguard.h | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) (limited to 'src/corelib/tools') diff --git a/src/corelib/tools/qscopeguard.h b/src/corelib/tools/qscopeguard.h index 4d2e715df1..6a5bc6cc61 100644 --- a/src/corelib/tools/qscopeguard.h +++ b/src/corelib/tools/qscopeguard.h @@ -43,6 +43,8 @@ #include +#include +#include QT_BEGIN_NAMESPACE @@ -98,18 +100,9 @@ template #if __has_cpp_attribute(nodiscard) Q_REQUIRED_RESULT #endif -QScopeGuard qScopeGuard(F &&f) +QScopeGuard::type> qScopeGuard(F &&f) { - return QScopeGuard(std::move(f)); -} - -template -#if __has_cpp_attribute(nodiscard) -Q_REQUIRED_RESULT -#endif -QScopeGuard qScopeGuard(const F &f) -{ - return QScopeGuard(f); + return QScopeGuard::type>(std::forward(f)); } QT_END_NAMESPACE -- cgit v1.2.3 From aadf21b25cad7026f07a5fe7bf19fbedfb1866b7 Mon Sep 17 00:00:00 2001 From: Linus Jahn Date: Fri, 31 Jan 2020 16:47:46 +0100 Subject: Fix 'the the' typo in comments Change-Id: I00fcb1c2374e7ca168b6240f9d41c0323fb0867c Reviewed-by: Giuseppe D'Angelo --- src/corelib/tools/qbitarray.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/corelib/tools') diff --git a/src/corelib/tools/qbitarray.cpp b/src/corelib/tools/qbitarray.cpp index f0b81cce66..ab3054d5be 100644 --- a/src/corelib/tools/qbitarray.cpp +++ b/src/corelib/tools/qbitarray.cpp @@ -305,7 +305,7 @@ void QBitArray::fill(bool value, int begin, int end) \since 5.11 Returns a pointer to a dense bit array for this QBitArray. Bits are counted - upwards from the least significant bit in each byte. The the number of bits + upwards from the least significant bit in each byte. The number of bits relevant in the last byte is given by \c{size() % 8}. \sa fromBits(), size() -- cgit v1.2.3 From a20dbcf7c77c9bc92cce87eed7bada4ab202f2af Mon Sep 17 00:00:00 2001 From: Sona Kurazyan Date: Mon, 3 Feb 2020 11:50:57 +0100 Subject: Deprecate QLinkedList [ChangeLog][Deprecation Notice] QLinkedList is deprecated and will be moved to Qt5Compat in Qt 6. It is recommended to use std::list instead. Task-number: QTBUG-81630 Task-number: QTBUG-80312 Change-Id: I2c2b64e51d1cc2fd305aee6a11e9a89788f51eb4 Reviewed-by: Lars Knoll --- src/corelib/tools/qcontainerfwd.h | 2 +- src/corelib/tools/qiterator.qdoc | 2 ++ src/corelib/tools/qlinkedlist.cpp | 14 ++++++++++++++ src/corelib/tools/qlinkedlist.h | 24 ++++++++++++++++++++---- 4 files changed, 37 insertions(+), 5 deletions(-) (limited to 'src/corelib/tools') diff --git a/src/corelib/tools/qcontainerfwd.h b/src/corelib/tools/qcontainerfwd.h index 532b4c95ce..00a8c85b66 100644 --- a/src/corelib/tools/qcontainerfwd.h +++ b/src/corelib/tools/qcontainerfwd.h @@ -47,7 +47,7 @@ QT_BEGIN_NAMESPACE template class QCache; template class QHash; -#ifndef QT_NO_LINKED_LIST +#if !defined(QT_NO_LINKED_LIST) && QT_DEPRECATED_SINCE(5, 15) template class QLinkedList; #endif template class QList; diff --git a/src/corelib/tools/qiterator.qdoc b/src/corelib/tools/qiterator.qdoc index b4d332b7b1..3531fb202c 100644 --- a/src/corelib/tools/qiterator.qdoc +++ b/src/corelib/tools/qiterator.qdoc @@ -203,6 +203,7 @@ /*! \class QLinkedListIterator \inmodule QtCore + \obsolete \brief The QLinkedListIterator class provides a Java-style const iterator for QLinkedList. @@ -416,6 +417,7 @@ /*! \class QMutableLinkedListIterator \inmodule QtCore + \obsolete \brief The QMutableLinkedListIterator class provides a Java-style non-const iterator for QLinkedList. diff --git a/src/corelib/tools/qlinkedlist.cpp b/src/corelib/tools/qlinkedlist.cpp index 3b1bc8aab1..6a423545da 100644 --- a/src/corelib/tools/qlinkedlist.cpp +++ b/src/corelib/tools/qlinkedlist.cpp @@ -45,6 +45,11 @@ QT_BEGIN_NAMESPACE +#if QT_DEPRECATED_SINCE(5, 15) + +QT_WARNING_PUSH +QT_WARNING_DISABLE_DEPRECATED + const QLinkedListData QLinkedListData::shared_null = { const_cast(&QLinkedListData::shared_null), const_cast(&QLinkedListData::shared_null), @@ -53,6 +58,7 @@ const QLinkedListData QLinkedListData::shared_null = { /*! \class QLinkedList \inmodule QtCore + \obsolete \brief The QLinkedList class is a template class that provides linked lists. \ingroup tools @@ -60,6 +66,8 @@ const QLinkedListData QLinkedListData::shared_null = { \reentrant + \note This class is obsolete, please use std::list instead. + QLinkedList\ is one of Qt's generic \l{container classes}. It stores a list of values and provides iterator-based access as well as \l{constant time} insertions and removals. @@ -720,6 +728,7 @@ const QLinkedListData QLinkedListData::shared_null = { /*! \class QLinkedList::iterator \inmodule QtCore + \obsolete \brief The QLinkedList::iterator class provides an STL-style non-const iterator for QLinkedList. QLinkedList features both \l{STL-style iterators} and @@ -965,6 +974,7 @@ const QLinkedListData QLinkedListData::shared_null = { /*! \class QLinkedList::const_iterator \inmodule QtCore + \obsolete \brief The QLinkedList::const_iterator class provides an STL-style const iterator for QLinkedList. QLinkedList features both \l{STL-style iterators} and @@ -1221,4 +1231,8 @@ const QLinkedListData QLinkedListData::shared_null = { \sa fromStdList() */ +QT_WARNING_POP + +#endif // QT_DEPRECATED_SINCE(5, 15) + QT_END_NAMESPACE diff --git a/src/corelib/tools/qlinkedlist.h b/src/corelib/tools/qlinkedlist.h index 8970d39be0..64c6b4d326 100644 --- a/src/corelib/tools/qlinkedlist.h +++ b/src/corelib/tools/qlinkedlist.h @@ -55,10 +55,22 @@ #include #include -QT_BEGIN_NAMESPACE +#if 0 +// This is needed because of QTBUG-80347 +#pragma qt_class(QLinkedList) +#pragma qt_class(QLinkedListData) +#pragma qt_class(QLinkedListNode) +#endif + +#if QT_DEPRECATED_SINCE(5, 15) + +QT_WARNING_PUSH +QT_WARNING_DISABLE_DEPRECATED -struct Q_CORE_EXPORT QLinkedListData +QT_BEGIN_NAMESPACE + +struct QT_DEPRECATED_VERSION_5_15 Q_CORE_EXPORT QLinkedListData { QLinkedListData *n, *p; QtPrivate::RefCount ref; @@ -69,7 +81,7 @@ struct Q_CORE_EXPORT QLinkedListData }; template -struct QLinkedListNode +struct QT_DEPRECATED_VERSION_5_15 QLinkedListNode { inline QLinkedListNode(const T &arg): t(arg) { } QLinkedListNode *n, *p; @@ -77,7 +89,7 @@ struct QLinkedListNode }; template -class QLinkedList +class QT_DEPRECATED_VERSION_X_5_15("Use std::list instead") QLinkedList { typedef QLinkedListNode Node; union { QLinkedListData *d; QLinkedListNode *e; }; @@ -594,6 +606,10 @@ QT_END_NAMESPACE Q_DECLARE_SEQUENTIAL_CONTAINER_METATYPE(QLinkedList) +QT_WARNING_POP + +#endif // QT_DEPRECATED_SINCE(5, 15) + #endif // QT_NO_LINKED_LIST #endif // QLINKEDLIST_H -- cgit v1.2.3 From 2c189ac79b2000041bba85b21b667cedf7fffbd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A5rten=20Nordheim?= Date: Fri, 31 Jan 2020 12:50:19 +0100 Subject: QMultiMap: fix QDoc warning The iterator is a QMultiMap iterator, not QMap, so the QDoc would complain. Change-Id: I1e3d2b454e21049d676387945e1e860e50854de8 Reviewed-by: Lars Knoll --- src/corelib/tools/qmap.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/corelib/tools') diff --git a/src/corelib/tools/qmap.cpp b/src/corelib/tools/qmap.cpp index e2b7705b55..9b9c67e42b 100644 --- a/src/corelib/tools/qmap.cpp +++ b/src/corelib/tools/qmap.cpp @@ -1999,7 +1999,7 @@ void QMapDataBase::freeData(QMapDataBase *d) \sa replace() */ -/*! \fn template typename QMap::iterator QMultiMap::insert(typename QMap::const_iterator pos, const Key &key, const T &value) +/*! \fn template typename QMultiMap::iterator QMultiMap::insert(typename QMultiMap::const_iterator pos, const Key &key, const T &value) \since 5.1 Inserts a new item with the key \a key and value \a value and with hint \a pos -- cgit v1.2.3