diff options
Diffstat (limited to 'src/corelib/global/qglobal.h')
-rw-r--r-- | src/corelib/global/qglobal.h | 64 |
1 files changed, 35 insertions, 29 deletions
diff --git a/src/corelib/global/qglobal.h b/src/corelib/global/qglobal.h index a2fe723bd8..450c1e586a 100644 --- a/src/corelib/global/qglobal.h +++ b/src/corelib/global/qglobal.h @@ -1,13 +1,12 @@ /**************************************************************************** ** -** Copyright (C) 2021 The Qt Company Ltd. +** Copyright (C) 2019 The Qt Company Ltd. ** Copyright (C) 2019 Intel Corporation. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the QtCore module of the Qt Toolkit. ** -** $QT_BEGIN_LICENSE:COMM$ -** +** $QT_BEGIN_LICENSE:LGPL$ ** Commercial License Usage ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the @@ -16,25 +15,26 @@ ** and conditions see https://www.qt.io/terms-conditions. For further ** information use the contact form at https://www.qt.io/contact-us. ** -** $QT_END_LICENSE$ -** -** -** -** -** -** -** -** -** -** -** -** -** -** -** -** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. ** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. ** +** $QT_END_LICENSE$ ** ****************************************************************************/ @@ -1102,13 +1102,16 @@ QForeachContainer<typename std::decay<T>::type> qMakeForeachContainer(T &&t) } +#define Q_FOREACH_JOIN(A, B) Q_FOREACH_JOIN_IMPL(A, B) +#define Q_FOREACH_JOIN_IMPL(A, B) A ## B + #if __cplusplus >= 201703L // Use C++17 if statement with initializer. User's code ends up in a else so // scoping of different ifs is not broken -#define Q_FOREACH(variable, container) \ -for (auto _container_ = QtPrivate::qMakeForeachContainer(container); \ - _container_.i != _container_.e; ++_container_.i) \ - if (variable = *_container_.i; false) {} else +#define Q_FOREACH_IMPL(variable, name, container) \ + for (auto name = QtPrivate::qMakeForeachContainer(container); \ + name.i != name.e; ++name.i) \ + if (variable = *name.i; false) {} else #else // Explanation of the control word: // - it's initialized to 1 @@ -1119,12 +1122,15 @@ for (auto _container_ = QtPrivate::qMakeForeachContainer(container); \ // the outer loop to continue executing // - if there was a break inside the inner loop, it will exit with control still // set to 1; in that case, the outer loop will invert it to 0 and will exit too -#define Q_FOREACH(variable, container) \ -for (auto _container_ = QtPrivate::qMakeForeachContainer(container); \ - _container_.control && _container_.i != _container_.e; \ - ++_container_.i, _container_.control ^= 1) \ - for (variable = *_container_.i; _container_.control; _container_.control = 0) +#define Q_FOREACH_IMPL(variable, name, container) \ +for (auto name = QtPrivate::qMakeForeachContainer(container); \ + name.control && name.i != name.e; \ + ++name.i, name.control ^= 1) \ + for (variable = *name.i; name.control; name.control = 0) #endif + +#define Q_FOREACH(variable, container) \ + Q_FOREACH_IMPL(variable, Q_FOREACH_JOIN(_container_, __LINE__), container) #endif // QT_NO_FOREACH #define Q_FOREVER for(;;) |