File indexing completed on 2026-08-05 09:27:13
0001
0002
0003
0004
0005 #ifndef QALGORITHMS_H
0006 #define QALGORITHMS_H
0007
0008 #if 0
0009 #pragma qt_class(QtAlgorithms)
0010 #endif
0011
0012 #include <QtCore/qglobal.h>
0013 #include <QtCore/q20bit.h>
0014 #include <QtCore/q20functional.h>
0015 #include <type_traits>
0016
0017 #define QT_HAS_CONSTEXPR_BITOPS
0018
0019 QT_BEGIN_NAMESPACE
0020
0021 template <typename ForwardIterator>
0022 Q_OUTOFLINE_TEMPLATE void qDeleteAll(ForwardIterator begin, ForwardIterator end)
0023 {
0024 while (begin != end) {
0025 delete *begin;
0026 ++begin;
0027 }
0028 }
0029
0030 template <typename Container>
0031 inline void qDeleteAll(const Container &c)
0032 {
0033 qDeleteAll(c.begin(), c.end());
0034 }
0035
0036
0037 Q_DECL_CONST_FUNCTION constexpr inline uint qPopulationCount(quint32 v) noexcept
0038 {
0039 return q20::popcount(v);
0040 }
0041
0042 Q_DECL_CONST_FUNCTION constexpr inline uint qPopulationCount(quint8 v) noexcept
0043 {
0044 return q20::popcount(v);
0045 }
0046
0047 Q_DECL_CONST_FUNCTION constexpr inline uint qPopulationCount(quint16 v) noexcept
0048 {
0049 return q20::popcount(v);
0050 }
0051
0052 Q_DECL_CONST_FUNCTION constexpr inline uint qPopulationCount(quint64 v) noexcept
0053 {
0054 return q20::popcount(v);
0055 }
0056
0057 Q_DECL_CONST_FUNCTION constexpr inline uint qPopulationCount(long unsigned int v) noexcept
0058 {
0059 return q20::popcount(v);
0060 }
0061
0062 constexpr inline uint qCountTrailingZeroBits(quint32 v) noexcept
0063 {
0064 return q20::countr_zero(v);
0065 }
0066
0067 constexpr inline uint qCountTrailingZeroBits(quint8 v) noexcept
0068 {
0069 return q20::countr_zero(v);
0070 }
0071
0072 constexpr inline uint qCountTrailingZeroBits(quint16 v) noexcept
0073 {
0074 return q20::countr_zero(v);
0075 }
0076
0077 constexpr inline uint qCountTrailingZeroBits(quint64 v) noexcept
0078 {
0079 return q20::countr_zero(v);
0080 }
0081
0082 constexpr inline uint qCountTrailingZeroBits(unsigned long v) noexcept
0083 {
0084 return q20::countr_zero(v);
0085 }
0086
0087 constexpr inline uint qCountLeadingZeroBits(quint32 v) noexcept
0088 {
0089 return q20::countl_zero(v);
0090 }
0091
0092 constexpr inline uint qCountLeadingZeroBits(quint8 v) noexcept
0093 {
0094 return q20::countl_zero(v);
0095 }
0096
0097 constexpr inline uint qCountLeadingZeroBits(quint16 v) noexcept
0098 {
0099 return q20::countl_zero(v);
0100 }
0101
0102 constexpr inline uint qCountLeadingZeroBits(quint64 v) noexcept
0103 {
0104 return q20::countl_zero(v);
0105 }
0106
0107 constexpr inline uint qCountLeadingZeroBits(unsigned long v) noexcept
0108 {
0109 return q20::countl_zero(v);
0110 }
0111
0112 template <typename InputIterator, typename Result, typename Separator = Result,
0113 typename Projection = q20::identity>
0114 Result qJoin(InputIterator first, InputIterator last, Result init, const Separator &separator = {},
0115 Projection p = {})
0116 {
0117 if (first != last) {
0118 init += std::invoke(p, *first);
0119 ++first;
0120 }
0121
0122 while (first != last) {
0123 init += separator;
0124 init += std::invoke(p, *first);
0125 ++first;
0126 }
0127
0128 return init;
0129 }
0130
0131 namespace QtPrivate {
0132
0133 template <typename T>
0134 constexpr
0135 std::enable_if_t<std::conjunction_v<std::is_integral<T>, std::is_unsigned<T>>, int>
0136 log2i(T x)
0137 {
0138
0139 Q_ASSERT(x > 0);
0140
0141 return int(sizeof(T) * 8 - 1 - qCountLeadingZeroBits(x));
0142 }
0143
0144 }
0145
0146 QT_END_NAMESPACE
0147
0148 #endif