diff options
Diffstat (limited to 'src/corelib/tools/qset.h')
-rw-r--r-- | src/corelib/tools/qset.h | 60 |
1 files changed, 33 insertions, 27 deletions
diff --git a/src/corelib/tools/qset.h b/src/corelib/tools/qset.h index 6640c8486d..83e574bf1c 100644 --- a/src/corelib/tools/qset.h +++ b/src/corelib/tools/qset.h @@ -41,10 +41,9 @@ #define QSET_H #include <QtCore/qhash.h> -#ifdef Q_COMPILER_INITIALIZER_LISTS -#include <initializer_list> -#endif +#include <QtCore/qcontainertools_impl.h> +#include <initializer_list> #include <iterator> QT_BEGIN_NAMESPACE @@ -56,19 +55,21 @@ class QSet typedef QHash<T, QHashDummyValue> Hash; public: - inline QSet() Q_DECL_NOTHROW {} -#ifdef Q_COMPILER_INITIALIZER_LISTS + inline QSet() noexcept {} inline QSet(std::initializer_list<T> list) + : QSet(list.begin(), list.end()) {} + template <typename InputIterator, QtPrivate::IfIsInputIterator<InputIterator> = true> + inline QSet(InputIterator first, InputIterator last) { - reserve(int(list.size())); - for (typename std::initializer_list<T>::const_iterator it = list.begin(); it != list.end(); ++it) - insert(*it); + QtPrivate::reserveIfForwardIterator(this, first, last); + for (; first != last; ++first) + insert(*first); } -#endif + // compiler-generated copy/move ctor/assignment operators are fine! // compiler-generated destructor is fine! - inline void swap(QSet<T> &other) Q_DECL_NOTHROW { q_hash.swap(other.q_hash); } + inline void swap(QSet<T> &other) noexcept { q_hash.swap(other.q_hash); } inline bool operator==(const QSet<T> &other) const { return q_hash == other.q_hash; } @@ -176,20 +177,20 @@ public: typedef std::reverse_iterator<const_iterator> const_reverse_iterator; inline iterator begin() { return q_hash.begin(); } - inline const_iterator begin() const Q_DECL_NOTHROW { return q_hash.begin(); } - inline const_iterator cbegin() const Q_DECL_NOTHROW { return q_hash.begin(); } - inline const_iterator constBegin() const Q_DECL_NOTHROW { return q_hash.constBegin(); } + inline const_iterator begin() const noexcept { return q_hash.begin(); } + inline const_iterator cbegin() const noexcept { return q_hash.begin(); } + inline const_iterator constBegin() const noexcept { return q_hash.constBegin(); } inline iterator end() { return q_hash.end(); } - inline const_iterator end() const Q_DECL_NOTHROW { return q_hash.end(); } - inline const_iterator cend() const Q_DECL_NOTHROW { return q_hash.end(); } - inline const_iterator constEnd() const Q_DECL_NOTHROW { return q_hash.constEnd(); } + inline const_iterator end() const noexcept { return q_hash.end(); } + inline const_iterator cend() const noexcept { return q_hash.end(); } + inline const_iterator constEnd() const noexcept { return q_hash.constEnd(); } reverse_iterator rbegin() { return reverse_iterator(end()); } reverse_iterator rend() { return reverse_iterator(begin()); } - const_reverse_iterator rbegin() const Q_DECL_NOTHROW { return const_reverse_iterator(end()); } - const_reverse_iterator rend() const Q_DECL_NOTHROW { return const_reverse_iterator(begin()); } - const_reverse_iterator crbegin() const Q_DECL_NOTHROW { return const_reverse_iterator(end()); } - const_reverse_iterator crend() const Q_DECL_NOTHROW { return const_reverse_iterator(begin()); } + const_reverse_iterator rbegin() const noexcept { return const_reverse_iterator(end()); } + const_reverse_iterator rend() const noexcept { return const_reverse_iterator(begin()); } + const_reverse_iterator crbegin() const noexcept { return const_reverse_iterator(end()); } + const_reverse_iterator crend() const noexcept { return const_reverse_iterator(begin()); } iterator erase(iterator i) { return erase(m2c(i)); } @@ -244,22 +245,25 @@ public: inline QSet<T> operator-(const QSet<T> &other) const { QSet<T> result = *this; result -= other; return result; } - QList<T> toList() const; - inline QList<T> values() const { return toList(); } - + QList<T> values() const; +#if QT_VERSION < QT_VERSION_CHECK(6,0,0) + Q_DECL_DEPRECATED_X("Use values() instead.") + QList<T> toList() const { return values(); } + Q_DECL_DEPRECATED_X("Use QSet<T>(list.begin(), list.end()) instead.") static QSet<T> fromList(const QList<T> &list); +#endif private: Hash q_hash; - static const_iterator m2c(iterator it) Q_DECL_NOTHROW + static const_iterator m2c(iterator it) noexcept { return const_iterator(typename Hash::const_iterator(it.i.i)); } bool isValidIterator(const iterator &i) const { return q_hash.isValidIterator(reinterpret_cast<const typename Hash::iterator&>(i)); } - bool isValidIterator(const const_iterator &i) const Q_DECL_NOTHROW + bool isValidIterator(const const_iterator &i) const noexcept { return q_hash.isValidIterator(reinterpret_cast<const typename Hash::const_iterator&>(i)); } @@ -267,7 +271,7 @@ private: template <typename T> uint qHash(const QSet<T> &key, uint seed = 0) -Q_DECL_NOEXCEPT_EXPR(noexcept(qHashRangeCommutative(key.begin(), key.end(), seed))) +noexcept(noexcept(qHashRangeCommutative(key.begin(), key.end(), seed))) { return qHashRangeCommutative(key.begin(), key.end(), seed); } @@ -367,7 +371,7 @@ Q_INLINE_TEMPLATE bool QSet<T>::contains(const QSet<T> &other) const } template <typename T> -Q_OUTOFLINE_TEMPLATE QList<T> QSet<T>::toList() const +Q_OUTOFLINE_TEMPLATE QList<T> QSet<T>::values() const { QList<T> result; result.reserve(size()); @@ -379,6 +383,7 @@ Q_OUTOFLINE_TEMPLATE QList<T> QSet<T>::toList() const return result; } +#if QT_VERSION < QT_VERSION_CHECK(6,0,0) template <typename T> Q_OUTOFLINE_TEMPLATE QSet<T> QList<T>::toSet() const { @@ -400,6 +405,7 @@ QList<T> QList<T>::fromSet(const QSet<T> &set) { return set.toList(); } +#endif Q_DECLARE_SEQUENTIAL_ITERATOR(Set) |