| 1 | // Copyright (C) 2021 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 3 | #ifndef Q20ITERATOR_H |
| 4 | #define Q20ITERATOR_H |
| 5 | |
| 6 | #include <QtCore/qglobal.h> |
| 7 | |
| 8 | #include <iterator> |
| 9 | |
| 10 | // |
| 11 | // W A R N I N G |
| 12 | // ------------- |
| 13 | // |
| 14 | // This file is not part of the Qt API. Types and functions defined in this |
| 15 | // file can reliably be replaced by their std counterparts, once available. |
| 16 | // You may use these definitions in your own code, but be aware that we |
| 17 | // will remove them once Qt depends on the C++ version that supports |
| 18 | // them in namespace std. There will be NO deprecation warning, the |
| 19 | // definitions will JUST go away. |
| 20 | // |
| 21 | // If you can't agree to these terms, don't use these definitions! |
| 22 | // |
| 23 | // We mean it. |
| 24 | // |
| 25 | |
| 26 | QT_BEGIN_NAMESPACE |
| 27 | |
| 28 | // like std::ssize |
| 29 | namespace q20 { |
| 30 | #ifdef __cpp_lib_ssize |
| 31 | using std::ssize; |
| 32 | #else |
| 33 | template<class C> constexpr auto ssize(const C &c) |
| 34 | -> std::common_type_t<std::ptrdiff_t, std::make_signed_t<decltype(c.size())>> |
| 35 | { return static_cast<std::common_type_t<std::ptrdiff_t, std::make_signed_t<decltype(c.size())>>>(c.size()); } |
| 36 | |
| 37 | template<class T, std::ptrdiff_t N> constexpr std::ptrdiff_t ssize(const T (&)[N]) noexcept |
| 38 | { return N; } |
| 39 | #endif |
| 40 | } // namespace q20 |
| 41 | |
| 42 | // like std::iter_reference_t |
| 43 | namespace q20 { |
| 44 | #ifdef __cpp_lib_ranges |
| 45 | using std::iter_reference_t; |
| 46 | #else |
| 47 | template <typename Dereferencable> // unconstrained (constraint requires concepts) |
| 48 | using iter_reference_t = decltype(*std::declval<Dereferencable&>()); |
| 49 | #endif // __cpp_lib_ranges |
| 50 | } // namespace q20 |
| 51 | |
| 52 | QT_END_NAMESPACE |
| 53 | |
| 54 | #endif /* Q20ITERATOR_H */ |
| 55 | |