Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qquick3dutils_p.h
Go to the documentation of this file.
1// Copyright (C) 2019 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4#ifndef QQUICK3DUTILS_P_H
5#define QQUICK3DUTILS_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <type_traits>
19
20#include <QtCore/QtGlobal>
21#include <private/qglobal_p.h>
22
23QT_BEGIN_NAMESPACE
24
25template <typename T, typename = void>
26struct hasFuzzyCompare : std::false_type {};
27
28template <typename T>
29struct hasFuzzyCompare<T, std::void_t<decltype(qFuzzyCompare(std::declval<T &>(), std::declval<T &>()))>> : std::true_type {};
30
31// Assigns 'updated' to 'orig' and returns true if they are different
32template <typename T, std::enable_if_t<!hasFuzzyCompare<T>::value, bool> = true>
33bool qUpdateIfNeeded(T &orig, T updated)
34{
35 if (orig == updated)
36 return false;
37 orig = updated;
38 return true;
39}
40
41// Assigns 'updated' to 'orig' and returns true if they are different, compared with qFuzzyCompare
42template <typename T, std::enable_if_t<hasFuzzyCompare<T>::value, bool> = true>
43bool qUpdateIfNeeded(T &orig, T updated)
44{
45 if (qFuzzyCompare(orig, updated))
46 return false;
47 orig = updated;
48 return true;
49}
50
51QT_END_NAMESPACE
52
53#endif // QQUICK3DUTILS_P_H
bool qUpdateIfNeeded(T &orig, T updated)