7#ifndef QHASHFUNCTIONS_H
8#define QHASHFUNCTIONS_H
10#include <QtCore/qstring.h>
11#include <QtCore/qstringfwd.h>
12#ifndef QT_BOOTSTRAPPED
13#include <QtCore/qbitarray.h>
21#pragma qt_class(QHashFunctions)
25#pragma warning( push )
26#pragma warning( disable : 4311
)
27#pragma warning( disable : 4127
)
32#if QT_DEPRECATED_SINCE(6
,6
)
33QT_DEPRECATED_VERSION_X_6_6(
"Use QHashSeed instead")
34Q_CORE_EXPORT
int qGlobalQHashSeed();
35QT_DEPRECATED_VERSION_X_6_6(
"Use QHashSeed instead")
36Q_CORE_EXPORT
void qSetGlobalQHashSeed(
int newSeed);
41 constexpr QHashSeed(size_t d = 0) : data(d) {}
42 constexpr operator size_t()
const noexcept {
return data; }
44 static Q_CORE_EXPORT QHashSeed globalSeed()
noexcept;
45 static Q_CORE_EXPORT
void setDeterministicGlobalSeed();
46 static Q_CORE_EXPORT
void resetRandomGlobalSeed();
52template <
typename Key,
typename T>
struct QHashHeterogeneousSearch : std::false_type {};
55template <>
struct QHashHeterogeneousSearch<QString, QStringView> : std::true_type {};
56template <>
struct QHashHeterogeneousSearch<QStringView, QString> : std::true_type {};
57template <>
struct QHashHeterogeneousSearch<QByteArray, QByteArrayView> : std::true_type {};
58template <>
struct QHashHeterogeneousSearch<QByteArrayView, QByteArray> : std::true_type {};
59#ifndef Q_PROCESSOR_ARM
60template <>
struct QHashHeterogeneousSearch<QString, QLatin1StringView> : std::true_type {};
61template <>
struct QHashHeterogeneousSearch<QStringView, QLatin1StringView> : std::true_type {};
62template <>
struct QHashHeterogeneousSearch<QLatin1StringView, QString> : std::true_type {};
63template <>
struct QHashHeterogeneousSearch<QLatin1StringView, QStringView> : std::true_type {};
71 if constexpr (
sizeof(
size_t) == 4) {
89template <
typename T1,
typename T2>
inline constexpr bool noexceptPairHash();
92Q_CORE_EXPORT Q_DECL_PURE_FUNCTION size_t qHashBits(
const void *p, size_t size, size_t seed = 0)
noexcept;
95template <
typename T1,
typename T2>
inline size_t qHash(
const std::pair<T1, T2> &key, size_t seed = 0)
96 noexcept(QHashPrivate::noexceptPairHash<T1, T2>());
98constexpr size_t qHash(
std::nullopt_t, size_t seed = 0)
noexcept;
99template <
typename T>
constexpr size_t qHash(
const std::optional<T> &key, size_t seed = 0)
100 noexcept(QHashPrivate::noexceptPairHash<T, T>());
103#define QT_MK_QHASH_COMPAT(X)
104 template <typename T, std::enable_if_t<std::is_same_v<T, X>, bool> = true>
105 constexpr size_t qHash(T key, size_t seed = 0
) noexcept
107 { return QHashPrivate::hash(size_t(key), 0
QT7_ONLY(+ seed)) QT6_ONLY(^ seed); }
110Q_DECL_CONST_FUNCTION
constexpr inline size_t qHash(
char key, size_t seed = 0)
noexcept
111{
return QHashPrivate::hash(size_t(key), seed); }
112Q_DECL_CONST_FUNCTION
constexpr inline size_t qHash(uchar key, size_t seed = 0)
noexcept
113{
return QHashPrivate::hash(size_t(key), seed); }
114Q_DECL_CONST_FUNCTION
constexpr inline size_t qHash(
signed char key, size_t seed = 0)
noexcept
115{
return QHashPrivate::hash(size_t(key), seed); }
116Q_DECL_CONST_FUNCTION
constexpr inline size_t qHash(ushort key, size_t seed = 0)
noexcept
117{
return QHashPrivate::hash(size_t(key), seed); }
118Q_DECL_CONST_FUNCTION
constexpr inline size_t qHash(
short key, size_t seed = 0)
noexcept
119{
return QHashPrivate::hash(size_t(key), seed); }
120Q_DECL_CONST_FUNCTION
constexpr inline size_t qHash(uint key, size_t seed = 0)
noexcept
121{
return QHashPrivate::hash(size_t(key), seed); }
122Q_DECL_CONST_FUNCTION
constexpr inline size_t qHash(
int key, size_t seed = 0)
noexcept
123{
return QHashPrivate::hash(size_t(key), seed); }
124Q_DECL_CONST_FUNCTION
constexpr inline size_t qHash(ulong key, size_t seed = 0)
noexcept
125{
return QHashPrivate::hash(size_t(key), seed); }
126Q_DECL_CONST_FUNCTION
constexpr inline size_t qHash(
long key, size_t seed = 0)
noexcept
127{
return QHashPrivate::hash(size_t(key), seed); }
128#undef QT_MK_QHASH_COMPAT
129Q_DECL_CONST_FUNCTION
constexpr inline size_t qHash(quint64 key, size_t seed = 0)
noexcept
131 if constexpr (
sizeof(quint64) >
sizeof(size_t))
133 return QHashPrivate::hash(size_t(key), seed);
135Q_DECL_CONST_FUNCTION
constexpr inline size_t qHash(qint64 key, size_t seed = 0)
noexcept
137 if constexpr (
sizeof(qint64) >
sizeof(size_t)) {
143 quint32 high = quint32(quint64(key) >> 32);
144 quint32 low = quint32(quint64(key));
145 quint32 signmask = qint32(high) >> 31;
146 signmask = QT_VERSION_MAJOR > 6 ? signmask : 0;
147 low ^= signmask ^ high;
148 return qHash(low, seed);
150 return qHash(quint64(key), seed);
152#ifdef QT_SUPPORTS_INT128
153constexpr size_t qHash(quint128 key, size_t seed = 0)
noexcept
155 return qHash(quint64(key + (key >> 64)), seed);
157constexpr size_t qHash(qint128 key, size_t seed = 0)
noexcept
161 quint64 high = quint64(quint128(key) >> 64);
162 quint64 low = quint64(quint128(key));
163 quint64 signmask = qint64(high) >> 63;
164 low += signmask ^ high;
165 return qHash(low, seed);
168Q_DECL_CONST_FUNCTION
inline size_t qHash(
float key, size_t seed = 0)
noexcept
173 memcpy(&k, &key,
sizeof(
float));
174 return QHashPrivate::hash(k, seed);
176Q_CORE_EXPORT Q_DECL_CONST_FUNCTION size_t qHash(
double key, size_t seed = 0)
noexcept;
177Q_CORE_EXPORT Q_DECL_CONST_FUNCTION size_t qHash(
long double key, size_t seed = 0)
noexcept;
178Q_DECL_CONST_FUNCTION
constexpr inline size_t qHash(
wchar_t key, size_t seed = 0)
noexcept
179{
return QHashPrivate::hash(size_t(key), seed); }
180Q_DECL_CONST_FUNCTION
constexpr inline size_t qHash(
char16_t key, size_t seed = 0)
noexcept
181{
return QHashPrivate::hash(size_t(key), seed); }
182Q_DECL_CONST_FUNCTION
constexpr inline size_t qHash(
char32_t key, size_t seed = 0)
noexcept
183{
return QHashPrivate::hash(size_t(key), seed); }
185Q_DECL_CONST_FUNCTION
constexpr inline size_t qHash(char8_t key, size_t seed = 0)
noexcept
186{
return QHashPrivate::hash(size_t(key), seed); }
188template <
class T>
inline size_t qHash(
const T *key, size_t seed = 0)
noexcept
190 return qHash(
reinterpret_cast<quintptr>(key), seed);
192#if QT_VERSION < QT_VERSION_CHECK(7
, 0
, 0
) && !defined(QT_BOOTSTRAPPED)
196template <
class T>
inline size_t qHash(T *key, size_t seed = 0)
noexcept
198 return qHash(
reinterpret_cast<quintptr>(key)) ^ seed;
201Q_DECL_CONST_FUNCTION
constexpr inline size_t qHash(std::nullptr_t, size_t seed = 0)
noexcept
205template <
class Enum, std::enable_if_t<std::is_enum_v<Enum>,
bool> =
true>
206Q_DECL_CONST_FUNCTION
constexpr inline size_t qHash(Enum e, size_t seed = 0)
noexcept
207{
return QHashPrivate::hash(qToUnderlying(e), seed); }
210Q_DECL_CONST_FUNCTION
constexpr inline size_t qHash(
const QChar key, size_t seed = 0)
noexcept {
return qHash(key.unicode(), seed); }
212#if QT_CORE_REMOVED_SINCE(6
, 4
)
213Q_CORE_EXPORT Q_DECL_PURE_FUNCTION size_t qHash(
const QByteArray &key, size_t seed = 0)
noexcept;
214Q_CORE_EXPORT Q_DECL_PURE_FUNCTION size_t qHash(
const QByteArrayView &key, size_t seed = 0)
noexcept;
216Q_CORE_EXPORT Q_DECL_PURE_FUNCTION size_t qHash(QByteArrayView key, size_t seed = 0)
noexcept;
217inline Q_DECL_PURE_FUNCTION size_t qHash(
const QByteArray &key, size_t seed = 0
218 QT6_DECL_NEW_OVERLOAD_TAIL)
noexcept
219{
return qHash(qToByteArrayViewIgnoringNull(key), seed); }
222Q_CORE_EXPORT Q_DECL_PURE_FUNCTION size_t qHash(QStringView key, size_t seed = 0)
noexcept;
223inline Q_DECL_PURE_FUNCTION size_t qHash(
const QString &key, size_t seed = 0)
noexcept
224{
return qHash(QStringView{key}, seed); }
225#ifndef QT_BOOTSTRAPPED
226Q_CORE_EXPORT Q_DECL_PURE_FUNCTION size_t qHash(
const QBitArray &key, size_t seed = 0)
noexcept;
228Q_CORE_EXPORT Q_DECL_PURE_FUNCTION size_t qHash(QLatin1StringView key, size_t seed = 0)
noexcept;
229Q_DECL_CONST_FUNCTION
constexpr inline size_t qHash(QKeyCombination key, size_t seed = 0)
noexcept
230{
return qHash(key.toCombined(), seed); }
231Q_CORE_EXPORT Q_DECL_PURE_FUNCTION uint qt_hash(QStringView key, uint chained = 0)
noexcept;
233template <
typename Enum>
234Q_DECL_CONST_FUNCTION
constexpr inline size_t qHash(QFlags<Enum> flags, size_t seed = 0)
noexcept
235{
return qHash(flags.toInt(), seed); }
239#if QT_VERSION < QT_VERSION_CHECK(7
, 0
, 0
)
243namespace QHashPrivate {
244template <
typename T,
typename =
void>
245constexpr inline bool HasQHashSingleArgOverload =
false;
248constexpr inline bool HasQHashSingleArgOverload<T, std::enable_if_t<
249 std::is_convertible_v<
decltype(qHash(std::declval<
const T &>())), size_t>
255template <
typename T,
typename...Args,
256 std::enable_if_t<QHashPrivate::HasQHashSingleArgOverload<T>
257 &&
sizeof...(Args) == 0 && !std::is_enum_v<T>,
bool> =
true>
258constexpr size_t qHash(
const T &t, size_t seed, Args&&...)
noexcept(
noexcept(qHash(t)))
259#ifdef QT_NO_SINGLE_ARGUMENT_QHASH_OVERLOAD
262{
return qHash(t) ^ seed; }
270constexpr size_t ex1to2arg(
const T &key, size_t seed)
272 return QT7_ONLY(qHash(key, seed)) QT6_ONLY(qHash(key, 0U) ^ seed);
277template <
typename T,
typename U,
typename =
void>
278struct is_equality_comparable_with : std::false_type {};
280template <
typename T,
typename U>
281struct is_equality_comparable_with<T, U,
283 decltype(
bool(std::declval<T>() == std::declval<U>())),
284 decltype(
bool(std::declval<U>() == std::declval<T>())),
285 decltype(
bool(std::declval<T>() != std::declval<U>())),
286 decltype(
bool(std::declval<U>() != std::declval<T>()))
291template <
typename Key,
typename T>
struct HeterogeneouslySearchableWithHelper
294 std::negation<std::is_same<Key, T>>,
296 detail::is_equality_comparable_with<Key, T>,
298 QHashHeterogeneousSearch<Key, T>
301template <
typename Key,
typename T>
307template <
typename Key,
typename K>
315bool qHashEquals(
const T &a,
const T &b)
320template <
typename T1,
typename T2, QHashPrivate::if_heterogeneously_searchable_with<T1, T2> =
true>
321bool qHashEquals(
const T1 &a,
const T2 &b)
327template <
typename Mixer>
struct QHashCombinerWithSeed :
private Mixer
329 using result_type =
typename Mixer::result_type;
331 constexpr QHashCombinerWithSeed(result_type s)
noexcept : seed(s) {}
333 template <
typename T>
334 constexpr result_type operator()(result_type result,
const T &t)
const
335 noexcept(
noexcept(qHash(t, seed)))
337 return Mixer::operator()(result, qHash(t, seed));
341#if QT_VERSION < QT_VERSION_CHECK(7
, 0
, 0
) || defined(QT_BOOTSTRAPPED)
354 template <
typename T>
362template <
typename Mixer>
using QHashCombiner = QHashCombinerWithSeed<Mixer>;
365struct QHashCombineMixer
367 typedef size_t result_type;
368 constexpr result_type operator()(result_type result, result_type hash)
const noexcept
371 return result ^ (hash + 0x9e3779b9 + (result << 6) + (result >> 2));
375using QHashCombineWithSeed = QHashCombinerWithSeed<QHashCombineMixer>;
377struct QHashCombineCommutativeMixer : std::plus<size_t>
384 typedef size_t result_type;
387using QHashCombineCommutativeWithSeed = QHashCombinerWithSeed<QHashCombineCommutativeMixer>;
389template <
typename...
T>
396template <
typename T,
typename Enable =
void>
397struct QNothrowHashable : std::false_type {};
408template <
typename... T>
413QtPrivate::QHashMultiReturnType<T...>
415qHashMulti(size_t seed,
const T &... args)
416 noexcept(std::conjunction_v<QtPrivate::QNothrowHashable<T>...>)
418 QtPrivate::QHashCombine hash(seed);
419 return ((seed = hash(seed, args)), ...), seed;
422template <
typename... T>
427QtPrivate::QHashMultiReturnType<T...>
429qHashMultiCommutative(size_t seed,
const T &... args)
430 noexcept(std::conjunction_v<QtPrivate::QNothrowHashable<T>...>)
432 QtPrivate::QHashCombineCommutative hash(seed);
433 return ((seed = hash(seed, args)), ...), seed;
436template <
typename InputIterator>
437inline size_t qHashRange(InputIterator first, InputIterator last, size_t seed = 0)
438 noexcept(
noexcept(qHash(*first, 0)))
440 return std::accumulate(first, last, seed, QtPrivate::QHashCombine(seed));
443template <
typename InputIterator>
444inline size_t qHashRangeCommutative(InputIterator first, InputIterator last, size_t seed = 0)
445 noexcept(
noexcept(qHash(*first, 0)))
447 return std::accumulate(first, last, seed, QtPrivate::QHashCombineCommutative(seed));
451template <
typename T1,
typename T2>
inline constexpr bool noexceptPairHash()
457constexpr size_t qHash(
std::nullopt_t, size_t seed)
noexcept
463 constexpr int NoValueHash = -2039;
464 return qHash(NoValueHash, seed);
467template <
typename T>
constexpr size_t qHash(
const std::optional<T> &key, size_t seed)
468 noexcept(QHashPrivate::noexceptPairHash<T, T>())
470 return key ? qHash(*key, seed) : qHash(
std::nullopt, seed);
473template <
typename T1,
typename T2>
inline size_t qHash(
const std::pair<T1, T2> &key, size_t seed)
474 noexcept(QHashPrivate::noexceptPairHash<T1, T2>())
476 return qHashMulti(seed, key.first, key.second);
479#define QT_SPECIALIZE_STD_HASH_TO_CALL_QHASH(Class, Arguments)
480 QT_BEGIN_INCLUDE_NAMESPACE
483 struct hash< QT_PREPEND_NAMESPACE(Class) > {
484 using argument_type = QT_PREPEND_NAMESPACE(Class);
485 using result_type = size_t;
486 size_t operator
()(Arguments s) const
487 noexcept(QT_PREPEND_NAMESPACE(
488 QtPrivate::QNothrowHashable_v)<argument_type>)
494 using QT_PREPEND_NAMESPACE(qHash);
495 return qHash(s, qHash(std::hash<int>{}(0
)));
499 QT_END_INCLUDE_NAMESPACE
502#define QT_SPECIALIZE_STD_HASH_TO_CALL_QHASH_BY_CREF(Class)
504#define QT_SPECIALIZE_STD_HASH_TO_CALL_QHASH_BY_VALUE(Class)
512#ifndef QT_BOOTSTRAPPED
518#if defined(Q_CC_MSVC)
519#pragma warning( pop )
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.
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.
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)
#define qPrintable(string)
#define QStringLiteral(str)
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.
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)