7#pragma qt_sync_skip_header_check
8#pragma qt_sync_stop_processing
11#ifndef QCONTAINERTOOLS_IMPL_H
12#define QCONTAINERTOOLS_IMPL_H
14#include <QtCore/qglobal.h>
15#include <QtCore/qtypeinfo.h>
17#include <QtCore/qxptype_traits.h>
30
31
32
33
34
35template<
typename T,
typename Cmp =
std::
less<>>
37 Cmp less = {})
noexcept
39 return !less(p, b) && less(p, e);
43
44
45
46
47
48template <
typename C,
typename T>
51 static_assert(std::is_same_v<
decltype(std::data(c)), T>);
55 return q_points_into_range(p,
std::data(c),
56 std::data(c) +
std::distance(
std::begin(c),
std::end(c)));
60QT_WARNING_DISABLE_GCC(
"-Wmaybe-uninitialized")
62template <
typename T,
typename N>
71template <
typename T,
typename N>
74 if constexpr (
QTypeInfo<T>::isRelocatable) {
75 static_assert(std::is_copy_constructible_v<T> || std::is_move_constructible_v<T>,
76 "Refusing to relocate this non-copy/non-move-constructible type.");
78 std::memcpy(
static_cast<
void *>(out),
79 static_cast<
const void *>(first),
83 q_uninitialized_move_if_noexcept_n(first, n, out);
85 std::destroy_n(first, n);
92
93
94
95
96
97
98
99
104 const auto cast = [](
T *
p) {
return reinterpret_cast<
uchar*>(
p); };
112
113
114
115
116
117
118
119
120
121
122
123template <
typename T,
typename Predicate>
126 static_assert(std::is_nothrow_destructible_v<T>,
127 "This algorithm requires that T has a non-throwing destructor");
128 Q_ASSERT(!q_points_into_range(out, first, last));
132 while (first != last) {
134 new (std::addressof(*out)) T(*first);
140 std::destroy(std::reverse_iterator(out), std::reverse_iterator(dest_begin));
146template<
typename iterator,
typename N>
155 Q_ASSERT(d_first < first);
156 using T =
typename std::iterator_traits<iterator>::value_type;
169 iterator intermediate;
171 Destructor(iterator &it)
noexcept : iter(
std::addressof(it)), end(it) { }
172 void commit()
noexcept { iter =
std::addressof(end); }
173 void freeze()
noexcept
175 intermediate = *iter;
176 iter =
std::addressof(intermediate);
178 ~Destructor()
noexcept
180 for (
const int step = *iter < end ? 1 : -1; *iter != end;) {
181 std::advance(*iter, step);
185 } destroyer(d_first);
187 const iterator d_last = d_first + n;
192 auto pair =
std::minmax(d_last, first);
196 iterator overlapBegin = pair.first;
197 iterator overlapEnd = pair.second;
200 while (d_first != overlapBegin) {
202 new (
std::addressof(*d_first)) T(
std::move_if_noexcept(*first));
212 while (d_first != d_last) {
213 *d_first =
std::move_if_noexcept(*first);
218 Q_ASSERT(d_first == destroyer.end + n);
221 while (first != overlapEnd)
226
227
228
229
230
231
232
233
234
235template<
typename T,
typename N>
238 static_assert(std::is_nothrow_destructible_v<T>,
239 "This algorithm requires that T has a non-throwing destructor");
241 if (n == N(0) || first == d_first || first ==
nullptr || d_first ==
nullptr)
244 if constexpr (
QTypeInfo<T>::isRelocatable) {
245 std::memmove(
static_cast<
void *>(d_first),
static_cast<
const void *>(first), n *
sizeof(T));
247 if (d_first < first) {
248 q_relocate_overlap_n_left_move(first, n, d_first);
250 auto rfirst =
std::make_reverse_iterator(first + n);
251 auto rd_first =
std::make_reverse_iterator(d_first + n);
252 q_relocate_overlap_n_left_move(rfirst, n, rd_first);
279template <
typename Container,
280 typename InputIterator,
281 IfIsNotForwardIterator<InputIterator> =
true>
286template <
typename Container,
287 typename ForwardIterator,
288 IfIsForwardIterator<ForwardIterator> =
true>
291 c->reserve(
static_cast<
typename Container::size_type>(
std::distance(f, l)));
327template <
typename T,
typename U>
331template<
typename T,
typename U>
334template <
typename Container,
typename Predicate>
342 const auto cbegin = c.cbegin();
343 const auto cend = c.cend();
344 const auto t_it =
std::find_if(cbegin, cend, pred);
345 auto result =
std::distance(cbegin, t_it);
346 if (result == c.size())
347 return result - result;
350 const auto e = c.end();
352 auto it =
std::next(c.begin(), result);
361 *dest =
std::move(*it);
366 result =
std::distance(dest, e);
371template <
typename Container,
typename T>
375 auto cmp = [&](
const auto &e) ->
bool {
return e == t; };
376 return sequential_erase_if(c, cmp);
379template <
typename Container,
typename T>
382 using CopyProxy = std::conditional_t<std::is_copy_constructible_v<T>, T,
const T &>;
383 return sequential_erase(c, CopyProxy(t));
386template <
typename Container,
typename T>
389 const auto cend = c.cend();
390 const auto it =
std::find(c.cbegin(), cend, t);
397template <
typename T,
typename Predicate>
400 qsizetype result = 0;
401 auto it = set.cbegin();
417template <
typename R,
typename F,
typename ... ArgTypes>
423template <
typename R,
typename F,
typename ...
ArgTypes>
425 std::is_invocable<F, ArgTypes...>,
429template <
typename Container,
typename Predicate>
434 using Iterator =
typename Container::iterator;
435 using Key =
typename Container::key_type;
436 using Value =
typename Container::mapped_type;
437 using KeyValuePair =
std::pair<
const Key &, Value &>;
439 typename Container::size_type result = 0;
442 const auto e = c.end();
444 if constexpr (is_invocable_explicit_r_v<
bool, Predicate &, Iterator &>) {
451 }
else if constexpr (is_invocable_explicit_r_v<
bool, Predicate &, KeyValuePair &&>) {
452 KeyValuePair p(it.key(), it.value());
453 if (pred(
std::move(p))) {
460 static_assert(type_dependent_false<Container>(),
"Predicate has an incompatible signature");
auto associative_erase_if(Container &c, Predicate &pred)
static int partiallyParsedDataCount(QStringConverter::State *state)
void q_uninitialized_relocate_n(T *first, N n, T *out)
qsizetype qset_erase_if(QSet< T > &set, Predicate &pred)
static constexpr bool q_points_into_range(const T *p, const T *b, const T *e, Cmp less={}) noexcept
auto sequential_erase_one(Container &c, const T &t)
void q_relocate_overlap_n_left_move(iterator first, N n, iterator d_first)
auto sequential_erase_if(Container &c, Predicate &pred)
auto sequential_erase_with_copy(Container &c, const T &t)
auto sequential_erase(Container &c, const T &t)
T * q_uninitialized_remove_copy_if(T *first, T *last, T *out, Predicate &pred)
static constexpr bool q_points_into_range(const T &p, const C &c) noexcept
void q_relocate_overlap_n(T *first, N n, T *d_first)
void reserveIfForwardIterator(Container *, InputIterator, InputIterator)
constexpr bool is_invocable_explicit_r_v
static bool nameMatch(const char *a, QAnyStringView b)
static const uchar utf8bom[]
static QChar * fromUtf32LE(QChar *out, QByteArrayView in, QStringConverter::State *state)
static QChar * fromUtf16LE(QChar *out, QByteArrayView in, QStringConverter::State *state)
static QByteArray parseHtmlMetaForEncoding(QByteArrayView data)
static QChar * fromUtf32BE(QChar *out, QByteArrayView in, QStringConverter::State *state)
static qsizetype toUtf8Len(qsizetype l)
static QChar * fromLocal8Bit(QChar *out, QByteArrayView in, QStringConverter::State *state)
static QChar * fromUtf16(QChar *out, QByteArrayView in, QStringConverter::State *state)
static qsizetype toLatin1Len(qsizetype l)
static bool nameMatch_impl_impl(const char *a, const Char *b, const Char *b_end)
static bool nameMatch_impl(const char *a, QLatin1StringView b)
static QChar * fromUtf32(QChar *out, QByteArrayView in, QStringConverter::State *state)
static char * toUtf32(char *out, QStringView in, QStringConverter::State *state)
static char * toUtf16LE(char *out, QStringView in, QStringConverter::State *state)
static qsizetype fromUtf8Len(qsizetype l)
static char * toLocal8Bit(char *out, QStringView in, QStringConverter::State *state)
static qsizetype toUtf16Len(qsizetype l)
static qsizetype fromLatin1Len(qsizetype l)
static char * toUtf16BE(char *out, QStringView in, QStringConverter::State *state)
static char * toUtf32LE(char *out, QStringView in, QStringConverter::State *state)
static qsizetype fromUtf32Len(qsizetype l)
static qsizetype availableCodecCount()
static QChar * fromUtf16BE(QChar *out, QByteArrayView in, QStringConverter::State *state)
static qsizetype toUtf32Len(qsizetype l)
static char * toUtf16(char *out, QStringView in, QStringConverter::State *state)
static qsizetype fromUtf16Len(qsizetype l)
static char * toUtf32BE(char *out, QStringView in, QStringConverter::State *state)
static void appendUtf16(const NoOutput &, char16_t)
static void appendUcs4(const NoOutput &, char32_t)
T * operator->() noexcept