8#include <QtCore/qhash.h>
9#include <QtCore/qcontainertools_impl.h>
10#include <QtCore/qttypetraits.h>
12#include <initializer_list>
21 typedef QHash<T, QHashDummyValue> Hash;
24 inline QSet()
noexcept {}
25 inline QSet(std::initializer_list<T> list)
26 : QSet(list.begin(), list.end()) {}
27 template <
typename InputIterator, QtPrivate::IfIsInputIterator<InputIterator> =
true>
28 inline QSet(InputIterator first, InputIterator last)
30 QtPrivate::reserveIfForwardIterator(
this, first, last);
31 for (; first != last; ++first)
38 inline void swap(QSet<T> &other)
noexcept { q_hash.swap(other.q_hash); }
42 template <
typename U = T, QTypeTraits::compare_eq_result_container<QSet, U> =
true>
43 friend bool comparesEqual(
const QSet &lhs,
const QSet &rhs)
noexcept
45 return lhs.q_hash == rhs.q_hash;
47 QT_DECLARE_EQUALITY_OPERATORS_HELPER(QSet, QSet, ,
noexcept,
48 template <
typename U = T, QTypeTraits::compare_eq_result_container<QSet, U> =
true>)
51 friend bool operator==(
const QSet &lhs,
const QSet &rhs)
noexcept;
52 friend bool operator!=(
const QSet &lhs,
const QSet &rhs)
noexcept;
55 inline qsizetype size()
const {
return q_hash.size(); }
57 inline bool isEmpty()
const {
return q_hash.isEmpty(); }
59 inline qsizetype capacity()
const {
return q_hash.capacity(); }
60 inline void reserve(qsizetype size);
61 inline void squeeze() { q_hash.squeeze(); }
63 inline void detach() { q_hash.detach(); }
64 inline bool isDetached()
const {
return q_hash.isDetached(); }
66 inline void clear() { q_hash.clear(); }
68 bool remove(
const T &value) {
return q_hash.remove(value); }
70 template <
typename Pred>
71 inline qsizetype removeIf(Pred predicate)
73 return QtPrivate::qset_erase_if(*
this, predicate);
76 inline bool contains(
const T &value)
const {
return q_hash.contains(value); }
78 bool contains(
const QSet<T> &set)
const;
84 typedef QHash<T, QHashDummyValue> Hash;
85 typename Hash::iterator i;
86 friend class const_iterator;
90 typedef std::forward_iterator_tag iterator_category;
91 typedef qptrdiff difference_type;
93 typedef const T *pointer;
94 typedef const T &reference;
97 inline iterator(
typename Hash::iterator o) : i(o) {}
98 inline iterator(
const iterator &o) : i(o.i) {}
99 inline iterator &operator=(
const iterator &o) { i = o.i;
return *
this; }
100 inline const T &operator*()
const {
return i.key(); }
101 inline const T *operator->()
const {
return &i.key(); }
102 inline bool operator==(
const iterator &o)
const {
return i == o.i; }
103 inline bool operator!=(
const iterator &o)
const {
return i != o.i; }
104 inline bool operator==(
const const_iterator &o)
const
106 inline bool operator!=(
const const_iterator &o)
const
108 inline iterator &operator++() { ++i;
return *
this; }
109 inline iterator operator++(
int) { iterator r = *
this; ++i;
return r; }
114 typedef QHash<T, QHashDummyValue> Hash;
115 typename Hash::const_iterator i;
116 friend class iterator;
117 friend class QSet<T>;
120 typedef std::forward_iterator_tag iterator_category;
121 typedef qptrdiff difference_type;
122 typedef T value_type;
123 typedef const T *pointer;
124 typedef const T &reference;
126 inline const_iterator() {}
127 inline const_iterator(
typename Hash::const_iterator o) : i(o) {}
128 inline const_iterator(
const const_iterator &o) : i(o.i) {}
129 inline const_iterator(
const iterator &o)
131 inline const_iterator &operator=(
const const_iterator &o) { i = o.i;
return *
this; }
132 inline const T &operator*()
const {
return i.key(); }
133 inline const T *operator->()
const {
return &i.key(); }
134 inline bool operator==(
const const_iterator &o)
const {
return i == o.i; }
135 inline bool operator!=(
const const_iterator &o)
const {
return i != o.i; }
136 inline const_iterator &operator++() { ++i;
return *
this; }
137 inline const_iterator operator++(
int) { const_iterator r = *
this; ++i;
return r; }
141 inline iterator begin() {
return q_hash.begin(); }
142 inline const_iterator begin()
const noexcept {
return q_hash.begin(); }
143 inline const_iterator cbegin()
const noexcept {
return q_hash.begin(); }
144 inline const_iterator constBegin()
const noexcept {
return q_hash.constBegin(); }
145 inline iterator end() {
return q_hash.end(); }
146 inline const_iterator end()
const noexcept {
return q_hash.end(); }
147 inline const_iterator cend()
const noexcept {
return q_hash.end(); }
148 inline const_iterator constEnd()
const noexcept {
return q_hash.constEnd(); }
150 iterator erase(const_iterator i)
152 Q_ASSERT(i != constEnd());
153 return q_hash.erase(i.i);
157 typedef iterator Iterator;
158 typedef const_iterator ConstIterator;
159 inline qsizetype count()
const {
return q_hash.size(); }
160 inline iterator insert(
const T &value)
161 {
return q_hash.insert(value, QHashDummyValue()); }
162 inline iterator insert(T &&value)
163 {
return q_hash.emplace(std::move(value), QHashDummyValue()); }
164 iterator find(
const T &value) {
return q_hash.find(value); }
165 const_iterator find(
const T &value)
const {
return q_hash.find(value); }
166 inline const_iterator constFind(
const T &value)
const {
return find(value); }
167 QSet<T> &unite(
const QSet<T> &other);
168 QSet &unite(QSet &&other);
169 QSet<T> &intersect(
const QSet<T> &other);
170 bool intersects(
const QSet<T> &other)
const;
171 QSet<T> &subtract(
const QSet<T> &other);
175 typedef T value_type;
176 typedef value_type *pointer;
177 typedef const value_type *const_pointer;
178 typedef value_type &reference;
179 typedef const value_type &const_reference;
180 typedef qptrdiff difference_type;
181 typedef qsizetype size_type;
183 inline bool empty()
const {
return isEmpty(); }
185 iterator insert(const_iterator,
const T &value) {
return insert(value); }
186 iterator insert(const_iterator, T &&value) {
return insert(std::move(value)); }
189 inline QSet<T> &operator<<(
const T &value) { insert(value);
return *
this; }
190 inline QSet<T> &operator|=(
const QSet<T> &other) { unite(other);
return *
this; }
191 QSet &operator|=(QSet &&other) {
return unite(std::move(other)); }
192 inline QSet<T> &operator|=(
const T &value) { insert(value);
return *
this; }
193 inline QSet<T> &operator&=(
const QSet<T> &other) { intersect(other);
return *
this; }
194 inline QSet<T> &operator&=(
const T &value)
195 { QSet<T> result;
if (contains(value)) result.insert(value);
return (*
this = result); }
196 inline QSet<T> &operator+=(
const QSet<T> &other) { unite(other);
return *
this; }
197 QSet &operator+=(QSet &&other) {
return unite(std::move(other)); }
198 inline QSet<T> &operator+=(
const T &value) { insert(value);
return *
this; }
199 inline QSet<T> &operator-=(
const QSet<T> &other) { subtract(other);
return *
this; }
200 inline QSet<T> &operator-=(
const T &value) { remove(value);
return *
this; }
202 friend QSet operator|(
const QSet &lhs,
const QSet &rhs) {
return QSet(lhs) |= rhs; }
203 friend QSet operator|(QSet &&lhs,
const QSet &rhs) { lhs |= rhs;
return std::move(lhs); }
204 friend QSet operator|(
const QSet &lhs, QSet &&rhs) {
return QSet(lhs) |= std::move(rhs); }
205 friend QSet operator|(QSet &&lhs, QSet &&rhs) {
return std::move(lhs) |= std::move(rhs); }
207 friend QSet operator&(
const QSet &lhs,
const QSet &rhs) {
return QSet(lhs) &= rhs; }
208 friend QSet operator&(QSet &&lhs,
const QSet &rhs) { lhs &= rhs;
return std::move(lhs); }
210 friend QSet operator+(
const QSet &lhs,
const QSet &rhs) {
return QSet(lhs) += rhs; }
211 friend QSet operator+(QSet &&lhs,
const QSet &rhs) { lhs += rhs;
return std::move(lhs); }
212 friend QSet operator+(
const QSet &lhs, QSet &&rhs) {
return QSet(lhs) += std::move(rhs); }
213 friend QSet operator+(QSet &&lhs, QSet &&rhs) {
return std::move(lhs) += std::move(rhs); }
215 friend QSet operator-(
const QSet &lhs,
const QSet &rhs) {
return QSet(lhs) -= rhs; }
216 friend QSet operator-(QSet &&lhs,
const QSet &rhs) { lhs -= rhs;
return std::move(lhs); }
218 inline QList<T> values()
const &;
219 inline QList<T> values() &&;
222 static inline QSet intersected_helper(
const QSet &lhs,
const QSet &rhs);
224 template <
typename E>
225 void _emplace_or_overwrite(E &&e);
230template <
typename InputIterator,
231 typename ValueType =
typename std::iterator_traits<InputIterator>::value_type,
232 QtPrivate::IfIsInputIterator<InputIterator> =
true>
239 return qHashRangeCommutative(key.begin(), key.end(), seed);
245Q_INLINE_TEMPLATE
void QSet<T>::reserve(qsizetype asize) { q_hash.reserve(asize); }
248Q_INLINE_TEMPLATE QSet<T> &QSet<T>::unite(
const QSet<T> &other)
250 if (!q_hash.isSharedWith(other.q_hash)) {
251 for (
const T &e : other)
258Q_INLINE_TEMPLATE
auto QSet<T>::unite(QSet &&other) -> QSet&
260 if (other.isDetached() && size() < other.size()) {
271 if (other.isDetached()) {
272 for (
auto it = other.q_hash.begin(), end = other.q_hash.end(); it != end; ++it)
273 _emplace_or_overwrite(std::move(it.i.node()->key));
275 for (
const auto &e : std::as_const(other))
276 _emplace_or_overwrite(e);
288Q_INLINE_TEMPLATE
void QSet<T>::_emplace_or_overwrite(E &&e)
290 const auto r = q_hash.tryEmplace(std::forward<E>(e));
295 typename Hash::Data::Bucket(r.iterator.i).node()->key = std::forward<E>(e);
300Q_INLINE_TEMPLATE QSet<T> &QSet<T>::intersect(
const QSet<T> &other)
302 if (q_hash.isSharedWith(other.q_hash)) {
304 }
else if (isEmpty() || other.isEmpty()) {
307 }
else if (q_hash.isDetached()) {
309 removeIf([&other] (
const T &e) {
return !other.contains(e); });
312 *
this = intersected_helper(*
this, other);
319auto QSet<T>::intersected_helper(
const QSet &lhs,
const QSet &rhs) -> QSet
323 const auto l_size = lhs.size();
324 const auto r_size = rhs.size();
325 r.reserve((std::min)(l_size, r_size));
330 if (l_size <= r_size) {
332 for (
const auto &e : lhs) {
338 for (
const auto &e : rhs) {
339 if (
const auto it = lhs.find(e); it != lhs.end())
348Q_INLINE_TEMPLATE
bool QSet<T>::intersects(
const QSet<T> &other)
const
350 const bool otherIsBigger = other.size() > size();
351 const QSet &smallestSet = otherIsBigger ? *
this : other;
352 const QSet &biggestSet = otherIsBigger ? other : *
this;
353 typename QSet::const_iterator i = smallestSet.cbegin();
354 typename QSet::const_iterator e = smallestSet.cend();
357 if (biggestSet.contains(*i))
366Q_INLINE_TEMPLATE QSet<T> &QSet<T>::subtract(
const QSet<T> &other)
368 if (q_hash.isSharedWith(other.q_hash)) {
371 for (
const auto &e : other)
378Q_INLINE_TEMPLATE
bool QSet<T>::contains(
const QSet<T> &other)
const
380 typename QSet<T>::const_iterator i = other.constBegin();
381 while (i != other.constEnd()) {
390QList<T> QSet<T>::values()
const &
393 result.reserve(size());
394 typename QSet<T>::const_iterator i = constBegin();
395 while (i != constEnd()) {
403QList<T> QSet<T>::values() &&
410 result.reserve(size());
411 for (
auto it = q_hash.begin(), end = q_hash.end(); it != end; ++it)
412 result.push_back(std::move(it.i.node()->key));
417Q_DECLARE_SEQUENTIAL_ITERATOR(Set)
419#if !defined(QT_NO_JAVA_STYLE_ITERATORS)
421class QMutableSetIterator
423 typedef typename QSet<T>::iterator iterator;
426 inline bool item_exists()
const {
return c->constEnd() != n; }
429 inline QMutableSetIterator(QSet<T> &container)
431 { i = c->begin(); n = c->end(); }
432 inline QMutableSetIterator &operator=(QSet<T> &container)
433 { c = &container; i = c->begin(); n = c->end();
return *
this; }
434 inline void toFront() { i = c->begin(); n = c->end(); }
435 inline void toBack() { i = c->end(); n = i; }
436 inline bool hasNext()
const {
return c->constEnd() != i; }
437 inline const T &next() { n = i++;
return *n; }
438 inline const T &peekNext()
const {
return *i; }
440 {
if (c->constEnd() != n) { i = c->erase(n); n = c->end(); } }
441 inline const T &value()
const { Q_ASSERT(item_exists());
return *n; }
442 inline bool findNext(
const T &t)
443 {
while (c->constEnd() != (n = i))
if (*i++ == t)
return true;
return false; }
450 return QtPrivate::qset_erase_if(set, pred);
bool requireCompleteTypes
ModuleUnitKind moduleUnitKind
void generate(FILE *out, FILE *jsonOutput)
QByteArray resolveIncludeNext(const QByteArray &filename, qsizetype startIndex, qsizetype *foundIndex=nullptr)
void setDebugIncludes(bool value)
void parseDefineArguments(Macro *m)
Symbols preprocessed(const QByteArray &filename, QFile *device)
void substituteUntilNewline(Symbols &substituted)
QList< QByteArray > frameworks
QHash< QByteArray, IncludeResolution > nonlocalIncludePathResolutionCache
static bool preprocessOnly
QByteArray resolveInclude(const QByteArray &filename, const QByteArray &relativeTo, qsizetype *foundIndex=nullptr)
static Symbols macroExpandIdentifier(Preprocessor *that, SymbolStack &symbols, int lineNum, QByteArray *macroName)
static Symbols tokenize(const QByteArray &input, int lineNum=1, TokenizeMode mode=TokenizeCpp)
static void macroExpand(Symbols *into, Preprocessor *that, const Symbols &toExpand, qsizetype &index, int lineNum, bool one, const QSet< QByteArray > &excludeSymbols=QSet< QByteArray >())
@ PreparePreprocessorStatement
@ TokenizePreprocessorStatement
The QCommandLineOption class defines a possible command-line option. \inmodule QtCore.
The QCommandLineParser class provides a means for handling the command line options.
\inmodule QtCore\reentrant
\macro QT_RESTRICTED_CAST_FROM_ASCII
QByteArray unquotedLexem()
const Symbol & symbol() const
bool dontReplaceSymbol(const QByteArray &name) const
const SafeSymbols & constTop() const
std::conditional_t< std::is_same_v< HashKey, q20::remove_cvref_t< KeyArgument > >, KeyArgument, HashKey > HeterogenousConstructProxy
Combined button and popup list for selecting options.
QString && asString(QString &&s)
constexpr QAnyStringArg qStringLikeToArg(QAnyStringView s) noexcept
const QString & asString(const QString &s)
std::is_same< Char, char32_t > IsCompatibleChar32TypeHelper
constexpr bool isLatin1(QLatin1StringView s) noexcept
QHash< MacroName, Macro > Macros
#define QT_SPECIALIZE_STD_HASH_TO_CALL_QHASH_BY_CREF(Class)
#define QT_SPECIALIZE_STD_HASH_TO_CALL_QHASH(Class, Arguments)
#define QT_SPECIALIZE_STD_HASH_TO_CALL_QHASH_BY_VALUE(Class)
#define QT_MK_QHASH_COMPAT(X)
QSet(InputIterator, InputIterator) -> QSet< ValueType >
size_t qHash(const QSet< T > &key, size_t seed=0) noexcept(noexcept(qHashRangeCommutative(key.begin(), key.end(), seed)))
qsizetype erase_if(QSet< T > &set, Predicate pred)
QString operator+(const QString &s1, QChar s2)
QString operator+(QString &&lhs, const QString &rhs)
qsizetype erase_if(QString &s, Predicate pred)
#define QT_UNICODE_LITERAL(str)
#define qPrintable(string)
QString operator+(QString &&lhs, QChar rhs)
QString operator+(QChar s1, const QString &s2)
#define QStringLiteral(str)
QString operator+(const QString &s1, const QString &s2)
qsizetype erase(QString &s, const T &t)
static QByteArray combinePath(const QString &infile, const QString &outfile)
static bool hasNext(const Symbols &symbols, int i)
static const Symbol & next(const Symbols &symbols, int &i)
int runMoc(int argc, char **argv)
static auto openFileForWriting(const QString &name)
void error(const char *msg="Invalid argument")
static QStringList argumentsFromCommandLineAndFile(const QStringList &arguments, bool &hasOptionFiles)
QByteArray composePreprocessorOutput(const Symbols &symbols)
int main(int argc, char *argv[])
[ctor_close]
Simple structure used by the Doc and DocParser classes.
constexpr QAnyStringArg(QAnyStringView v) noexcept
constexpr QLatin1StringArg(QLatin1StringView v) noexcept
QLatin1StringArg()=default
constexpr QStringViewArg(QStringView v) noexcept
bool operator==(const SubArray &other) const
SubArray(const QByteArray &a)
SubArray(const QByteArray &a, qsizetype from, qsizetype len)
QByteArrayView unquotedLexemView() const
Symbol(int lineNum, Token token)
operator SubArray() const
QByteArrayView lexemView() const
void mergeStringLiteral(const Symbol &next)
bool operator==(const Symbol &o) const
Symbol(int lineNum, Token token, const QByteArray &lexem, qsizetype from, qsizetype len)
QByteArray unquotedLexem() const
Symbol(int lineNum, Token token, const QByteArray &lexem)
size_t qHash(const SubArray &key, size_t seed=0)
Q_DECLARE_TYPEINFO(Symbol, Q_RELOCATABLE_TYPE)
Q_DECLARE_TYPEINFO(SafeSymbols, Q_RELOCATABLE_TYPE)
#define FOR_ALL_TOKENS(F)