swift
Loading...
Searching...
No Matches
sequence.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (C) 2013 swift Project Community / Contributors
2// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3
5
6#ifndef SWIFT_MISC_SEQUENCE_H
7#define SWIFT_MISC_SEQUENCE_H
8
9#include <algorithm>
10#include <functional>
11#include <initializer_list>
12#include <iterator>
13#include <type_traits>
14#include <utility>
15
16#include <QVector>
17
18#include "misc/containerbase.h"
22
24#define SWIFT_TEMPLATE_SEQUENCE_MIXINS(NS, T, List, Extern) \
25 namespace NS \
26 { \
27 class List; \
28 } \
29 namespace swift::misc::private_ns \
30 { \
31 Extern template struct CValueObjectMetaInfo<NS::List>; \
32 Extern template struct CValueObjectMetaInfo<CSequence<NS::T>>; \
33 Extern template struct MetaTypeHelper<NS::List>; \
34 Extern template struct MetaTypeHelper<CSequence<NS::T>>; \
35 } \
36 namespace swift::misc::mixin \
37 { \
38 Extern template class MetaType<NS::List>; \
39 Extern template class MetaType<CSequence<NS::T>>; \
40 Extern template class DBusOperators<CSequence<NS::T>>; \
41 Extern template class JsonOperators<CSequence<NS::T>>; \
42 Extern template class String<CSequence<NS::T>>; \
43 Extern template class DataStreamOperators<CSequence<NS::T>>; \
44 Extern template class Icon<CSequence<NS::T>>; \
45 }
47
53
58#if defined(Q_OS_WIN) && defined(Q_CC_GNU)
59# define SWIFT_DECLARE_SEQUENCE_MIXINS(Namespace, T, List)
60# define SWIFT_DEFINE_SEQUENCE_MIXINS(Namespace, T, List)
61#else
62# define SWIFT_DECLARE_SEQUENCE_MIXINS(Namespace, T, List) SWIFT_TEMPLATE_SEQUENCE_MIXINS(Namespace, T, List, extern)
63# define SWIFT_DEFINE_SEQUENCE_MIXINS(Namespace, T, List) SWIFT_TEMPLATE_SEQUENCE_MIXINS(Namespace, T, List, )
64#endif
65
66namespace swift::misc
67{
68 namespace private_ns
69 {
71 SWIFT_MISC_EXPORT SWIFT_NO_INLINE QVector<int> findIndices(int size, const std::function<bool(int)> &predicate);
72
74 SWIFT_MISC_EXPORT SWIFT_NO_INLINE QVector<int> sortIndices(int size, const std::function<bool(int, int)> &cmp);
75 } // namespace private_ns
76
81 template <class T>
82 class CSequence :
83 public CContainerBase<CSequence<T>>,
84 public mixin::DataStreamOperators<CSequence<T>>,
85 public mixin::Icon<CSequence<T>>
86 {
87 public:
89 using key_type = T;
90
92 using value_type = T;
93
95 using reference = T &;
96
98 using const_reference = const T &;
99
101 using pointer = T *;
102
104 using const_pointer = const T *;
105
108
111
114
117
119 using difference_type = ptrdiff_t;
120
122 using size_type = int;
123
125 CSequence() = default;
126
128 CSequence(std::initializer_list<T> il) : m_impl(il) {}
129
131 CSequence(QList<T> &&list) : m_impl(std::move(list)) {}
132
134 CSequence(const QList<T> &list) : m_impl(list) {}
135
137 template <typename It>
138 CSequence(It first, It last) : m_impl(first, last)
139 {}
140
142 CSequence(const CSequence &other) = default;
143
145 CSequence(CSequence &&other) = default;
146
148 CSequence &operator=(const CSequence &other) = default;
149
151 CSequence &operator=(CSequence &&other) = default;
152
154 ~CSequence() = default;
155
157 QVector<T> toVector() const & { return m_impl; }
158
160 QVector<T> toVector() && { return std::move(m_impl); }
161
163 iterator begin() { return m_impl.begin(); }
164
166 const_iterator begin() const { return m_impl.begin(); }
167
169 const_iterator cbegin() const { return m_impl.cbegin(); }
170
172 iterator end() { return m_impl.end(); }
173
175 const_iterator end() const { return m_impl.end(); }
176
178 const_iterator cend() const { return m_impl.cend(); }
179
181 reverse_iterator rbegin() { return m_impl.rbegin(); }
182
184 const_reverse_iterator rbegin() const { return m_impl.rbegin(); }
185
187 const_reverse_iterator crbegin() const { return m_impl.crbegin(); }
188
190 reverse_iterator rend() { return m_impl.rend(); }
191
193 const_reverse_iterator rend() const { return m_impl.rend(); }
194
196 const_reverse_iterator crend() const { return m_impl.crend(); }
197
199 void swap(CSequence &other) noexcept { m_impl.swap(other.m_impl); }
200
201#ifdef __GNUC__
202# pragma GCC diagnostic push
203# pragma GCC diagnostic ignored "-Wstrict-overflow"
204#endif
205
208 {
209 Q_ASSERT(index >= 0 && index < m_impl.size());
210 return m_impl[index];
211 }
212
215 {
216 Q_ASSERT(index >= 0 && index < m_impl.size());
217 return m_impl[index];
218 }
219
220#ifdef __GNUC__
221# pragma GCC diagnostic pop
222#endif
223
226 {
227 Q_ASSERT(!empty());
228 return m_impl.front();
229 }
230
233 {
234 Q_ASSERT(!empty());
235 return m_impl.front();
236 }
237
240 {
241 static const value_type def {};
242 return empty() ? def : m_impl.front();
243 }
244
246 value_type frontOrDefault(value_type def) const { return empty() ? def : m_impl.front(); }
247
250 {
251 Q_ASSERT(!empty());
252 return m_impl.back();
253 }
254
257 {
258 Q_ASSERT(!empty());
259 return m_impl.back();
260 }
261
264 {
265 static const value_type def {};
266 return empty() ? def : m_impl.back();
267 }
268
270 value_type backOrDefault(value_type def) const { return empty() ? def : m_impl.back(); }
271
273 size_type size() const { return m_impl.size(); }
274
276 int sizeInt() const { return static_cast<int>(this->size()); }
277
279 QString sizeString() const { return QString::number(m_impl.size()); }
280
282 bool empty() const { return m_impl.isEmpty(); }
283
285 bool isEmpty() const { return empty(); }
286
288 void clear() { m_impl.clear(); }
289
291 void truncate(size_type maxSize)
292 {
293 if (size() > maxSize)
294 {
295 erase(begin() + maxSize, end());
296 }
297 }
298
301 iterator insert(iterator before, const T &value) { return m_impl.insert(before, value); }
302
305 iterator insert(iterator before, T &&value) { return m_impl.insert(before, std::move(value)); }
306
308 void push_back(const T &value) { m_impl.push_back(value); }
309
311 void push_front(const T &value) { insert(begin(), value); }
312
314 void push_front(const CSequence &other) { std::copy(other.begin(), other.end(), std::front_inserter(*this)); }
315
317 void push_frontMaxElements(const T &value, int maxElements)
318 {
319 Q_ASSERT(maxElements > 1);
320 if (this->size() >= (maxElements - 1))
321 {
322 this->truncate(maxElements - 1);
323 }
324 this->push_front(value);
325 }
326
328 void push_backMaxElements(const T &value, int maxElements)
329 {
330 Q_ASSERT(maxElements > 1);
331 while (this->size() >= (maxElements - 1))
332 {
333 this->pop_front();
334 }
335 this->push_back(value);
336 }
337
339 void push_back(T &&value) { m_impl.push_back(std::move(value)); }
340
342 void push_front(T &&value) { insert(begin(), std::move(value)); }
343
345 void push_back(const CSequence &other) { std::copy(other.begin(), other.end(), std::back_inserter(*this)); }
346
349 void push_back(CSequence &&other) { std::move(other.begin(), other.end(), std::back_inserter(*this)); }
350
352 template <typename I>
353 void push_back(const CRange<I> &range)
354 {
355 std::copy(range.begin(), range.end(), std::back_inserter(*this));
356 }
357
359 CSequence join(const CSequence &other) const
360 {
361 CSequence copy(*this);
362 copy.push_back(other);
363 return copy;
364 }
365
367 template <typename I>
368 CSequence join(const CRange<I> &range) const
369 {
370 CSequence copy(*this);
371 copy.push_back(range);
372 return copy;
373 }
374
376 void pop_back()
377 {
378 Q_ASSERT(!empty());
379 m_impl.pop_back();
380 }
381
384 {
385 Q_ASSERT(!empty());
386 erase(begin());
387 }
388
391 iterator erase(iterator pos) { return m_impl.erase(pos); }
392
395 iterator erase(iterator it1, iterator it2) { return m_impl.erase(it1, it2); }
396
398 iterator find(const T &object) { return std::find(begin(), end(), object); }
399
401 const_iterator find(const T &object) const { return std::find(cbegin(), cend(), object); }
402
404
406 template <class Predicate>
407 CSequence findBy(Predicate p) const
408 {
409 QVector<T> found;
410 for (int i : private_ns::findIndices(size(), [&p, this](int i) { return p((*this)[i]); }))
411 {
412 found.push_back((*this)[i]);
413 }
414 return found;
415 }
416
419 template <class Predicate, class VariantMap>
420 int applyIf(Predicate p, const VariantMap &newValues, bool skipEqualValues = false)
421 {
422 int count = 0;
423 for (auto &value : *this)
424 {
425 if (p(value) && !value.apply(newValues, skipEqualValues).isEmpty())
426 {
427 count++;
428 }
429 }
430 return count;
431 }
432
439 template <class K1, class V1, class VariantMap>
440 int applyIf(K1 key1, V1 value1, const VariantMap &newValues, bool skipEqualValues = false)
441 {
442 return applyIf(swift::misc::predicates::MemberEqual(key1, value1), newValues, skipEqualValues);
443 }
444
447 int remove(const T &object)
448 {
449 const auto newEnd = std::remove(begin(), end(), object);
450 const auto count = std::distance(newEnd, end());
451 erase(newEnd, end());
452 return count;
453 }
454
457 template <class Predicate>
458 int removeIf(Predicate p)
459 {
460 const auto newEnd = std::remove_if(begin(), end(), p);
461 const auto count = std::distance(newEnd, end());
462 erase(newEnd, end());
463 return count;
464 }
465
467 template <class K0, class V0, class... KeysValues>
468 int removeIf(K0 k0, V0 v0, KeysValues... keysValues)
469 {
470 // using-declaration doesn't play nicely with injected template names
471 return CSequence::CContainerBase::removeIf(k0, v0, keysValues...);
472 }
473
476 int removeIfIn(const CSequence &other)
477 {
478 return removeIf([&other](const T &v) { return other.contains(v); });
479 }
480
483 void removeIfInSubset(const CSequence &other)
484 {
485 erase(swift::misc::removeIfIn(begin(), end(), other.begin(), other.end()), end());
486 }
487
490 int replace(const T &original, const T &replacement)
491 {
492 int count = 0;
493 for (auto &element : *this)
494 {
495 if (element == original)
496 {
497 element = replacement;
498 count++;
499 }
500 }
501 return count;
502 }
503
506 template <class Predicate>
507 int replaceIf(Predicate p, const T &replacement)
508 {
509 int count = 0;
510 for (auto &element : *this)
511 {
512 if (p(element))
513 {
514 element = replacement;
515 count++;
516 }
517 }
518 return count;
519 }
520
526 template <class K1, class V1>
527 int replaceIf(K1 key1, V1 value1, const T &replacement)
528 {
529 return replaceIf(swift::misc::predicates::MemberEqual(key1, value1), replacement);
530 }
531
533 void replaceOrAdd(const T &original, const T &replacement)
534 {
535 if (this->contains(original))
536 {
537 replace(original, replacement);
538 }
539 else
540 {
541 push_back(replacement);
542 }
543 }
544
546 void replaceOrAdd(const T &replacement) { this->replaceOrAdd(replacement, replacement); }
547
549 void replaceOrAdd(const CSequence<T> &replacements)
550 {
551 for (const T &replacement : replacements)
552 {
553 this->replaceOrAdd(replacement, replacement);
554 }
555 }
556
561 template <class K1, class V1>
562 void replaceOrAdd(K1 key1, V1 value1, const T &replacement)
563 {
564 if (this->contains(key1, value1))
565 {
566 replaceIf(key1, value1, replacement);
567 }
568 else
569 {
570 push_back(replacement);
571 }
572 }
573
575 void reverse() { std::reverse(begin(), end()); }
576
578 Q_REQUIRED_RESULT CSequence reversed() const
579 {
580 CSequence result = *this;
581 result.reverse();
582 return result;
583 }
584
586 template <class Predicate>
587 void sort(Predicate p)
588 {
589 QVector<T> temp;
590 temp.reserve(size());
591 for (int i :
592 private_ns::sortIndices(size(), [&p, this](int a, int b) { return p((*this)[a], (*this)[b]); }))
593 {
594 temp.push_back(std::move((*this)[i]));
595 }
596 m_impl = std::move(temp);
597 }
598
602 template <class K1, class... Keys>
603 void sortBy(K1 key1, Keys... keys)
604 {
606 }
607
609 template <class Predicate>
610 Q_REQUIRED_RESULT CSequence sorted(Predicate p) const
611 {
612 CSequence result = *this;
613 result.sort(p);
614 return result;
615 }
616
620 template <class K1, class... Keys>
621 CSequence sortedBy(K1 key1, Keys... keys) const
622 {
623 return sorted(swift::misc::predicates::MemberLess(key1, keys...));
624 }
625
627 template <class Predicate>
628 void partiallySort(size_type n, Predicate p)
629 {
630 std::partial_sort(begin(), begin() + std::min(n, size()), end(), p);
631 }
632
637 template <class K1, class... Keys>
638 void partiallySortBy(size_type n, K1 key1, Keys... keys)
639 {
641 }
642
644 template <class Predicate>
645 Q_REQUIRED_RESULT CSequence partiallySorted(size_type n, Predicate p) const
646 {
647 CSequence result = *this;
648 result.partiallySort(n, p);
649 return result;
650 }
651
656 template <class K1, class... Keys>
657 CSequence partiallySortedBy(size_type n, K1 key1, Keys... keys) const
658 {
660 }
661
664 template <class U, class Key0, class... Keys>
665 bool unorderedEqualsByKeys(const U &other, Key0 k0, Keys... keys) const
666 {
667 if (equalPointers(this, &other))
668 {
669 return true;
670 }
671 if (size() != other.size())
672 {
673 return false;
674 }
675 return sorted(k0, keys...).equalsByKeys(other.sorted(k0, keys...));
676 }
677
679 template <class Predicate>
680 auto separate(Predicate p) const -> QMap<decltype(p(std::declval<T>())), CSequence>
681 {
683 auto copy = *this;
684 std::stable_sort(copy.begin(), copy.end(), [p](const T &a, const T &b) { return p(a) < p(b); });
685 for (auto it = copy.cbegin(); it != copy.cend();)
686 {
687 auto mid = std::adjacent_find(it, copy.cend(), [p](const T &a, const T &b) { return p(a) != p(b); });
688 result.insert(p(*it), makeRange(it, mid));
689 it = mid;
690 }
691 return result;
692 }
693
695 template <class Key>
697 {
698 return separateBy([k](const T &v) { return std::invoke(k, v); });
699 }
700
702 void detach() { m_impl.detach(); }
703
705 friend bool operator==(const CSequence &a, const CSequence &b) { return a.m_impl == b.m_impl; }
706
708 friend bool operator!=(const CSequence &a, const CSequence &b) { return a.m_impl != b.m_impl; }
709
711 friend bool operator<(const CSequence &a, const CSequence &b) { return a.m_impl < b.m_impl; }
712
714 friend bool operator>(const CSequence &a, const CSequence &b) { return a.m_impl > b.m_impl; }
715
717 friend bool operator<=(const CSequence &a, const CSequence &b) { return a.m_impl <= b.m_impl; }
718
720 friend bool operator>=(const CSequence &a, const CSequence &b) { return a.m_impl >= b.m_impl; }
721
723 void marshalToDataStream(QDataStream &stream) const { stream << m_impl; }
724
726 void unmarshalFromDataStream(QDataStream &stream) { stream >> m_impl; }
727
728 private:
729 QList<T> m_impl;
730 };
731} // namespace swift::misc
732
733Q_DECLARE_SEQUENTIAL_CONTAINER_METATYPE(swift::misc::CSequence)
734
735#endif // SWIFT_MISC_SEQUENCE_H
Base class for CCollection and CSequence adding mutating operations and CValueObject facility on top ...
bool equalsByKeys(const T &other, Key0 k0, Keys... keys) const
Return true if this container equals another container, considering only the given element members.
Definition range.h:138
static bool equalPointers(const T *a, const U *b)
Definition range.h:169
bool contains(const T &object) const
Return true if there is an element equal to given object. Uses the most efficient implementation avai...
Definition range.h:109
A range is a conceptual container which does not contain any elements of its own, but is constructed ...
Definition range.h:199
const_iterator end() const
Begin and end iterators.
Definition range.h:222
const_iterator begin() const
Begin and end iterators.
Definition range.h:220
Generic sequential container with value semantics.
Definition sequence.h:86
void push_front(const CSequence &other)
Inserts all elements from another sequence at the beginning of this sequence.
Definition sequence.h:314
typename QVector< T >::reverse_iterator reverse_iterator
STL compatibility.
Definition sequence.h:116
iterator erase(iterator pos)
Remove the element pointed to by the given iterator.
Definition sequence.h:391
void push_back(T &&value)
Move-appends an element at the end of the sequence.
Definition sequence.h:339
int applyIf(K1 key1, V1 value1, const VariantMap &newValues, bool skipEqualValues=false)
Modify by applying a value map to each element matching a particular key/value pair.
Definition sequence.h:440
int removeIf(K0 k0, V0 v0, KeysValues... keysValues)
Remove elements matching some particular key/value pair(s).
Definition sequence.h:468
CSequence sortedBy(K1 key1, Keys... keys) const
Return a copy sorted by some particular key(s).
Definition sequence.h:621
CSequence(const QList< T > &list)
By QList of type T.
Definition sequence.h:134
friend bool operator>(const CSequence &a, const CSequence &b)
Greater than operator.
Definition sequence.h:714
int replaceIf(K1 key1, V1 value1, const T &replacement)
Replace elements matching a particular key/value pair.
Definition sequence.h:527
size_type size() const
Returns number of elements in the sequence.
Definition sequence.h:273
void sortBy(K1 key1, Keys... keys)
In-place sort by some particular key(s).
Definition sequence.h:603
void push_front(T &&value)
Move-insert as first element.
Definition sequence.h:342
Q_REQUIRED_RESULT CSequence partiallySorted(size_type n, Predicate p) const
Return a copy with the smallest n elements at the beginning and sorted.
Definition sequence.h:645
void pop_back()
Removes an element at the end of the sequence.
Definition sequence.h:376
~CSequence()=default
Destructor.
T key_type
STL compatibility.
Definition sequence.h:89
CSequence(std::initializer_list< T > il)
Initializer list constructor.
Definition sequence.h:128
CSequence()=default
Default constructor.
friend bool operator>=(const CSequence &a, const CSequence &b)
Greater or equal operator.
Definition sequence.h:720
void unmarshalFromDataStream(QDataStream &stream)
Unmarshal a value from a QDataStream.
Definition sequence.h:726
const_reverse_iterator crend() const
Returns const iterator at the end of the reversed sequence.
Definition sequence.h:196
void partiallySortBy(size_type n, K1 key1, Keys... keys)
In-place partially sort by some particular key(s).
Definition sequence.h:638
int replace(const T &original, const T &replacement)
Replace elements matching the given element with a replacement.
Definition sequence.h:490
typename QVector< T >::const_reverse_iterator const_reverse_iterator
STL compatibility.
Definition sequence.h:113
reference operator[](size_type index)
Access an element by its index.
Definition sequence.h:207
iterator begin()
Returns iterator at the beginning of the sequence.
Definition sequence.h:163
int replaceIf(Predicate p, const T &replacement)
Replace elements for which a given predicate returns true.
Definition sequence.h:507
const_reference frontOrDefault() const
Access the first element, or a default-initialized value if the sequence is empty.
Definition sequence.h:239
T value_type
STL compatilibty.
Definition sequence.h:92
T * pointer
STL compatibility.
Definition sequence.h:101
const_reverse_iterator crbegin() const
Returns const iterator at the beginning of the reversed sequence.
Definition sequence.h:187
CSequence findBy(Predicate p) const
Return a copy containing only those elements for which a given predicate returns true.
Definition sequence.h:407
void replaceOrAdd(const T &original, const T &replacement)
Replace elements matching the given element. If there is no match, push the new element on the end.
Definition sequence.h:533
iterator erase(iterator it1, iterator it2)
Remove the range of elements between two iterators.
Definition sequence.h:395
reverse_iterator rbegin()
Returns iterator at the beginning of the reversed sequence.
Definition sequence.h:181
typename QVector< T >::const_iterator const_iterator
STL compatibility.
Definition sequence.h:107
const_iterator find(const T &object) const
Return an iterator to the first element equal to the given object, or the end iterator if not found....
Definition sequence.h:401
void truncate(size_type maxSize)
Changes the size of the sequence, if it is bigger than the given size.
Definition sequence.h:291
void push_back(const CSequence &other)
Appends all elements from another sequence at the end of this sequence.
Definition sequence.h:345
const T & const_reference
STL compatibility.
Definition sequence.h:98
void push_back(CSequence &&other)
Appends all elements from another sequence at the end of this sequence. This version moves elements i...
Definition sequence.h:349
CSequence partiallySortedBy(size_type n, K1 key1, Keys... keys) const
Return a copy partially sorted by some particular key(s).
Definition sequence.h:657
bool unorderedEqualsByKeys(const U &other, Key0 k0, Keys... keys) const
Return true if this container equals another container, considering only the given element members....
Definition sequence.h:665
const_iterator end() const
Returns const iterator one past the end of the sequence.
Definition sequence.h:175
Q_REQUIRED_RESULT CSequence sorted(Predicate p) const
Return a copy sorted by a given comparator predicate.
Definition sequence.h:610
const T * const_pointer
STL compatibility.
Definition sequence.h:104
T & reference
STL compatibility.
Definition sequence.h:95
void removeIfInSubset(const CSequence &other)
Remove all elements if they are in other.
Definition sequence.h:483
bool empty() const
Returns true if the sequence is empty.
Definition sequence.h:282
CSequence(CSequence &&other)=default
Move constructor.
CSequence & operator=(const CSequence &other)=default
Copy assignment.
value_type backOrDefault(value_type def) const
Access the last element, or a default value if the sequence is empty.
Definition sequence.h:270
friend bool operator<(const CSequence &a, const CSequence &b)
Less than operator.
Definition sequence.h:711
iterator insert(iterator before, T &&value)
Moves an element into the sequence.
Definition sequence.h:305
auto separate(Predicate p) const -> QMap< decltype(p(std::declval< T >())), CSequence >
Split up the sequence into subsequences for which the given predicate returns the same value.
Definition sequence.h:680
value_type frontOrDefault(value_type def) const
Access the first element, or a default-initialized value if the sequence is empty.
Definition sequence.h:246
friend bool operator==(const CSequence &a, const CSequence &b)
Equals operator.
Definition sequence.h:705
int removeIf(Predicate p)
Remove elements for which a given predicate returns true.
Definition sequence.h:458
void push_back(const T &value)
Appends an element at the end of the sequence.
Definition sequence.h:308
const_reference back() const
Access the last element.
Definition sequence.h:256
const_iterator cbegin() const
Returns const iterator at the beginning of the sequence.
Definition sequence.h:169
friend bool operator<=(const CSequence &a, const CSequence &b)
Less or equal than operator.
Definition sequence.h:717
friend bool operator!=(const CSequence &a, const CSequence &b)
Not equals operator.
Definition sequence.h:708
CSequence(QList< T > &&list)
By QList of type T.
Definition sequence.h:131
CSequence(const CSequence &other)=default
Copy constructor.
void marshalToDataStream(QDataStream &stream) const
Marshal a value to a QDataStream.
Definition sequence.h:723
QVector< T > toVector() const &
Copy of internal vector.
Definition sequence.h:157
const_reverse_iterator rend() const
Returns const iterator at the end of the reversed sequence.
Definition sequence.h:193
CSequence(It first, It last)
Range constructor.
Definition sequence.h:138
void partiallySort(size_type n, Predicate p)
In-place move the smallest n elements to the beginning and sort them.
Definition sequence.h:628
void swap(CSequence &other) noexcept
Swap this sequence with another.
Definition sequence.h:199
CSequence join(const CRange< I > &range) const
Concatenates a sequence and a range and returns the result.
Definition sequence.h:368
int applyIf(Predicate p, const VariantMap &newValues, bool skipEqualValues=false)
Modify by applying a value map to each element for which a given predicate returns true.
Definition sequence.h:420
int size_type
STL compatibility.
Definition sequence.h:122
typename QVector< T >::iterator iterator
STL compatibility.
Definition sequence.h:110
QVector< T > toVector() &&
Copy of internal vector.
Definition sequence.h:160
const_reference backOrDefault() const
Access the last element, or a default value if the sequence is empty.
Definition sequence.h:263
void push_frontMaxElements(const T &value, int maxElements)
Insert as first element by keep maxElements.
Definition sequence.h:317
reference front()
Access the first element.
Definition sequence.h:225
const_reference front() const
Access the first element.
Definition sequence.h:232
void clear()
Removes all elements in the sequence.
Definition sequence.h:288
reverse_iterator rend()
Returns iterator at the end of the reversed sequence.
Definition sequence.h:190
QString sizeString() const
Convenience function.
Definition sequence.h:279
iterator find(const T &object)
Return an iterator to the first element equal to the given object, or the end iterator if not found....
Definition sequence.h:398
void push_front(const T &value)
Insert as first element.
Definition sequence.h:311
reference back()
Access the last element.
Definition sequence.h:249
void push_back(const CRange< I > &range)
Appends all elements from a range at the end of this sequence.
Definition sequence.h:353
Q_REQUIRED_RESULT CSequence reversed() const
Reversed order.
Definition sequence.h:578
void reverse()
In-place reverse.
Definition sequence.h:575
int remove(const T &object)
Remove all elements equal to the given object, if it is contained.
Definition sequence.h:447
void replaceOrAdd(K1 key1, V1 value1, const T &replacement)
Replace elements matching a particular key/value pair. If there is no match, push the new element on ...
Definition sequence.h:562
ptrdiff_t difference_type
STL compatibility.
Definition sequence.h:119
void replaceOrAdd(const T &replacement)
Replace elements matching the given element. If there is no match, push the new element on the end.
Definition sequence.h:546
const_iterator cend() const
Returns const iterator one past the end of the sequence.
Definition sequence.h:178
int removeIfIn(const CSequence &other)
Remove all elements if they are in other.
Definition sequence.h:476
void push_backMaxElements(const T &value, int maxElements)
Insert as last element by keep maxElements.
Definition sequence.h:328
bool isEmpty() const
Synonym for empty.
Definition sequence.h:285
iterator insert(iterator before, const T &value)
Inserts an element into the sequence.
Definition sequence.h:301
void replaceOrAdd(const CSequence< T > &replacements)
Replace or add given elements.
Definition sequence.h:549
CSequence join(const CSequence &other) const
Concatenates two sequences and returns the result.
Definition sequence.h:359
auto separateBy(Key k) const -> QMap< decltype(std::invoke(k, std::declval< T >())), CSequence >
Split up the sequence into subsequences of elements having the same value for the given key.
Definition sequence.h:696
CSequence & operator=(CSequence &&other)=default
Move assignment.
const_iterator begin() const
Returns const iterator at the beginning of the sequence.
Definition sequence.h:166
iterator end()
Returns iterator one past the end of the sequence.
Definition sequence.h:172
int sizeInt() const
Avoid compiler warnings when using with int.
Definition sequence.h:276
const_reference operator[](size_type index) const
Access an element by its index.
Definition sequence.h:214
void pop_front()
Removes an element at the front of the sequence.
Definition sequence.h:383
void sort(Predicate p)
In-place sort by a given comparator predicate.
Definition sequence.h:587
const_reverse_iterator rbegin() const
Returns const iterator at the beginning of the reversed sequence.
Definition sequence.h:184
CRTP class template to generate non-member QDataStream streaming operators.
CRTP class template from which a derived class can inherit icon-related functions.
Definition mixinicon.h:28
auto MemberEqual(Ts... vs)
Predicate which tests whether some member functions return some values.
Definition predicates.h:26
auto MemberLess(Ts... vs)
Predicate which compares the return values of some member functions of two objects.
Definition predicates.h:43
Free functions in swift::misc.
auto makeRange(I begin, I2 end) -> CRange< I >
Returns a CRange constructed from begin and end iterators of deduced types.
Definition range.h:328
auto removeIfIn(I begin1, I end1, J begin2, J end2)
Removes those elements in range 1 that appear also in range 2 leaving only those that do not appear i...
Definition algorithm.h:25
typedef const_reverse_iterator
void push_back(QList< T >::parameter_type value)
void reserve(qsizetype size)
typedef reverse_iterator
QString number(double n, char format, int precision)
QVector< int > sortIndices(int size, const std::function< bool(int, int)> &cmp)
Decouple sorting from value type.
Definition sequence.cpp:20
QVector< int > findIndices(int size, const std::function< bool(int)> &predicate)
Decouple finding from value type.
Definition sequence.cpp:12
#define SWIFT_NO_INLINE
Prevent function inlining.
#define SWIFT_MISC_EXPORT
Export a class or function from the library.