libquentier  0.5.0
The library for rich desktop clients of Evernote service
Compat.h
1 /*
2  * Copyright 2020 Dmitry Ivanov
3  *
4  * This file is part of libquentier
5  *
6  * libquentier is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation, version 3 of the License.
9  *
10  * libquentier is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with libquentier. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #ifndef LIB_QUENTIER_UTILITY_COMPAT_H
20 #define LIB_QUENTIER_UTILITY_COMPAT_H
21 
22 #include <QHash>
23 #include <QString>
24 #include <QtGlobal>
25 
26 #if QT_VERSION < QT_VERSION_CHECK(5, 7, 0)
27 #include <type_traits>
28 #endif
29 
30 // Compatibility with older Qt versions
31 
32 #if QT_VERSION < QT_VERSION_CHECK(5, 7, 0)
33 
34 // this adds const to non-const objects (like std::as_const)
35 template <typename T>
36 Q_DECL_CONSTEXPR typename std::add_const<T>::type & qAsConst(T & t)
37  Q_DECL_NOTHROW
38 {
39  return t;
40 }
41 
42 // prevent rvalue arguments:
43 template <typename T>
44 void qAsConst(const T &&) = delete;
45 
46 #endif
47 
48 // Compatibility with boost parts which require to take a hash of QString
49 
50 inline std::size_t hash_value(QString x) noexcept
51 {
52  return qHash(x);
53 }
54 
55 #endif // LIB_QUENTIER_UTILITY_COMPAT_H