diff options
Diffstat (limited to 'src/corelib/tools')
-rw-r--r-- | src/corelib/tools/qbitarray.cpp | 2 | ||||
-rw-r--r-- | src/corelib/tools/qcontainerfwd.h | 2 | ||||
-rw-r--r-- | src/corelib/tools/qhash.h | 2 | ||||
-rw-r--r-- | src/corelib/tools/qiterator.qdoc | 2 | ||||
-rw-r--r-- | src/corelib/tools/qlinkedlist.cpp | 14 | ||||
-rw-r--r-- | src/corelib/tools/qlinkedlist.h | 24 | ||||
-rw-r--r-- | src/corelib/tools/qmap.cpp | 2 | ||||
-rw-r--r-- | src/corelib/tools/qscopeguard.h | 32 | ||||
-rw-r--r-- | src/corelib/tools/qscopeguard.qdoc | 41 |
9 files changed, 90 insertions, 31 deletions
diff --git a/src/corelib/tools/qbitarray.cpp b/src/corelib/tools/qbitarray.cpp index a1dd537d4d..12ad6f4573 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() diff --git a/src/corelib/tools/qcontainerfwd.h b/src/corelib/tools/qcontainerfwd.h index f6efa99b6a..d6e30d77e3 100644 --- a/src/corelib/tools/qcontainerfwd.h +++ b/src/corelib/tools/qcontainerfwd.h @@ -47,7 +47,7 @@ QT_BEGIN_NAMESPACE template <class Key, class T> class QCache; template <class Key, class T> class QHash; -#ifndef QT_NO_LINKED_LIST +#if !defined(QT_NO_LINKED_LIST) && QT_DEPRECATED_SINCE(5, 15) template <class T> class QLinkedList; #endif template <class Key, class T> class QMap; diff --git a/src/corelib/tools/qhash.h b/src/corelib/tools/qhash.h index c56324eef7..47fa0520d9 100644 --- a/src/corelib/tools/qhash.h +++ b/src/corelib/tools/qhash.h @@ -1245,6 +1245,7 @@ Q_OUTOFLINE_TEMPLATE int QMultiHash<Key, T>::count(const Key &akey) const return cnt; } +#if !defined(QT_NO_JAVA_STYLE_ITERATORS) template <class Key, class T> class QHashIterator { @@ -1419,6 +1420,7 @@ public: } #endif }; +#endif // !QT_NO_JAVA_STYLE_ITERATORS template <class Key, class T> uint qHash(const QHash<Key, T> &key, uint seed = 0) 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 *>(&QLinkedListData::shared_null), const_cast<QLinkedListData *>(&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\<T\> 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 e3713d2c1c..fd3df74059 100644 --- a/src/corelib/tools/qlinkedlist.h +++ b/src/corelib/tools/qlinkedlist.h @@ -55,10 +55,22 @@ #include <iterator> #include <list> -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 <typename T> -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 T> -class QLinkedList +class QT_DEPRECATED_VERSION_X_5_15("Use std::list instead") QLinkedList { typedef QLinkedListNode<T> Node; union { QLinkedListData *d; QLinkedListNode<T> *e; }; @@ -591,6 +603,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 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 <class Key, class T> typename QMap<Key, T>::iterator QMultiMap<Key, T>::insert(typename QMap<Key, T>::const_iterator pos, const Key &key, const T &value) +/*! \fn template <class Key, class T> typename QMultiMap<Key, T>::iterator QMultiMap<Key, T>::insert(typename QMultiMap<Key, T>::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 diff --git a/src/corelib/tools/qscopeguard.h b/src/corelib/tools/qscopeguard.h index 40d2747b1d..6a5bc6cc61 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 <sergio.martins@kdab.com> +** 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. @@ -42,13 +43,11 @@ #include <QtCore/qglobal.h> +#include <type_traits> +#include <utility> QT_BEGIN_NAMESPACE - -template <typename F> class QScopeGuard; -template <typename F> QScopeGuard<F> qScopeGuard(F f); - template <typename F> class #if __has_cpp_attribute(nodiscard) @@ -59,13 +58,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,26 +86,23 @@ 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>(F); }; +#ifdef __cpp_deduction_guides +template <typename F> QScopeGuard(F(&)()) -> QScopeGuard<F(*)()>; +#endif template <typename F> #if __has_cpp_attribute(nodiscard) Q_REQUIRED_RESULT #endif -QScopeGuard<F> qScopeGuard(F f) +QScopeGuard<typename std::decay<F>::type> qScopeGuard(F &&f) { - return QScopeGuard<F>(std::move(f)); + return QScopeGuard<typename std::decay<F>::type>(std::forward<F>(f)); } QT_END_NAMESPACE 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 <sergio.martins@kdab.com> +** 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<F> 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 <typename F> QScopeGuard<F>::QScopeGuard(F &&f) + \fn template <typename F> QScopeGuard<F>::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 <typename F> void QScopeGuard<F>::dismiss() @@ -51,23 +76,17 @@ QT_BEGIN_NAMESPACE of the scope. \ingroup misc - QScopeGuard<F> 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<F> 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 |