File indexing completed on 2024-04-21 04:36:01

0001 /*
0002     Copyright (c) 2017 Kevin Funk <kfunk@.kde.org
0003 
0004     This library is free software; you can redistribute it and/or modify it
0005     under the terms of the GNU Library General Public License as published by
0006     the Free Software Foundation; either version 2 of the License, or (at your
0007     option) any later version.
0008 
0009     This library is distributed in the hope that it will be useful, but WITHOUT
0010     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0011     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
0012     License for more details.
0013 
0014     You should have received a copy of the GNU Library General Public License
0015     along with this library; see the file COPYING.LIB.  If not, write to the
0016     Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
0017     02110-1301, USA.
0018 */
0019 
0020 #ifndef KDEVELOP_QTCOMPAT_P_H
0021 #define KDEVELOP_QTCOMPAT_P_H
0022 
0023 #include <qglobal.h>
0024 
0025 #include <QDir>
0026 
0027 #if QT_VERSION < QT_VERSION_CHECK(5,7,0)
0028 namespace QtPrivate
0029 {
0030 template <typename T> struct QAddConst {
0031     typedef const T Type;
0032 };
0033 }
0034 
0035 // this adds const to non-const objects (like std::as_const)
0036 template <typename T>
0037 Q_DECL_CONSTEXPR typename QtPrivate::QAddConst<T>::Type &qAsConst(T &t) Q_DECL_NOTHROW { return t; }
0038 // prevent rvalue arguments:
0039 template <typename T>
0040 void qAsConst(const T &&) Q_DECL_EQ_DELETE;
0041 #endif
0042 
0043 // compat for Q_FALLTHROUGH
0044 #if QT_VERSION < QT_VERSION_CHECK(5,8,0)
0045 
0046 #if defined(__has_cpp_attribute)
0047 #    if __has_cpp_attribute(fallthrough)
0048 #        define Q_FALLTHROUGH() [[fallthrough]]
0049 #    elif __has_cpp_attribute(clang::fallthrough)
0050 #        define Q_FALLTHROUGH() [[clang::fallthrough]]
0051 #    elif __has_cpp_attribute(gnu::fallthrough)
0052 #        define Q_FALLTHROUGH() [[gnu::fallthrough]]
0053 #    endif
0054 #endif
0055 
0056 #ifndef Q_FALLTHROUGH
0057 #    if defined(__GNUC__) && !defined(__INTEL_COMPILER) && (((__GNUC__ * 100) + __GNUC_MINOR__) >= 700)
0058 #        define Q_FALLTHROUGH() __attribute__((fallthrough))
0059 #    else
0060 #        define Q_FALLTHROUGH() (void)0
0061 #    endif
0062 #endif
0063 
0064 #endif
0065 
0066 namespace QtCompat {
0067 // TODO: Just use QDir::listSeparator once we depend on Qt 5.6
0068 Q_DECL_CONSTEXPR inline QChar listSeparator() Q_DECL_NOTHROW
0069 {
0070 #if QT_VERSION < QT_VERSION_CHECK(5,6,0)
0071 #ifdef Q_OS_WIN
0072     return QLatin1Char(';');
0073 #else
0074     return QLatin1Char(':');
0075 #endif
0076 #else
0077     return QDir::listSeparator();
0078 #endif
0079 }
0080 }
0081 
0082 #endif