swift
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"
20 #include "misc/mixin/mixinicon.h"
21 #include "misc/swiftmiscexport.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 
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 
66 namespace 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  typedef T key_type;
90 
92  typedef T value_type;
93 
95  typedef T &reference;
96 
98  typedef const T &const_reference;
99 
101  typedef T *pointer;
102 
104  typedef const T *const_pointer;
105 
107  typedef typename QVector<T>::const_iterator const_iterator;
108 
110  typedef typename QVector<T>::iterator iterator;
111 
113  typedef typename QVector<T>::const_reverse_iterator const_reverse_iterator;
114 
116  typedef typename QVector<T>::reverse_iterator reverse_iterator;
117 
119  typedef ptrdiff_t difference_type;
120 
122  typedef int size_type;
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) { erase(begin() + maxSize, end()); }
294  }
295 
298  iterator insert(iterator before, const T &value) { return m_impl.insert(before, value); }
299 
302  iterator insert(iterator before, T &&value) { return m_impl.insert(before, std::move(value)); }
303 
305  void push_back(const T &value) { m_impl.push_back(value); }
306 
308  void push_front(const T &value) { insert(begin(), value); }
309 
311  void push_front(const CSequence &other) { std::copy(other.begin(), other.end(), std::front_inserter(*this)); }
312 
314  void push_frontMaxElements(const T &value, int maxElements)
315  {
316  Q_ASSERT(maxElements > 1);
317  if (this->size() >= (maxElements - 1)) { this->truncate(maxElements - 1); }
318  this->push_front(value);
319  }
320 
322  void push_backMaxElements(const T &value, int maxElements)
323  {
324  Q_ASSERT(maxElements > 1);
325  while (this->size() >= (maxElements - 1)) { this->pop_front(); }
326  this->push_back(value);
327  }
328 
330  void push_back(T &&value) { m_impl.push_back(std::move(value)); }
331 
333  void push_front(T &&value) { insert(begin(), std::move(value)); }
334 
336  void push_back(const CSequence &other) { std::copy(other.begin(), other.end(), std::back_inserter(*this)); }
337 
340  void push_back(CSequence &&other) { std::move(other.begin(), other.end(), std::back_inserter(*this)); }
341 
343  template <typename I>
344  void push_back(const CRange<I> &range)
345  {
346  std::copy(range.begin(), range.end(), std::back_inserter(*this));
347  }
348 
350  CSequence join(const CSequence &other) const
351  {
352  CSequence copy(*this);
353  copy.push_back(other);
354  return copy;
355  }
356 
358  template <typename I>
359  CSequence join(const CRange<I> &range) const
360  {
361  CSequence copy(*this);
362  copy.push_back(range);
363  return copy;
364  }
365 
367  void pop_back()
368  {
369  Q_ASSERT(!empty());
370  m_impl.pop_back();
371  }
372 
374  void pop_front()
375  {
376  Q_ASSERT(!empty());
377  erase(begin());
378  }
379 
382  iterator erase(iterator pos) { return m_impl.erase(pos); }
383 
386  iterator erase(iterator it1, iterator it2) { return m_impl.erase(it1, it2); }
387 
389  iterator find(const T &object) { return std::find(begin(), end(), object); }
390 
392  const_iterator find(const T &object) const { return std::find(cbegin(), cend(), object); }
393 
395 
397  template <class Predicate>
398  CSequence findBy(Predicate p) const
399  {
400  QVector<T> found;
401  for (int i : private_ns::findIndices(size(), [&p, this](int i) { return p((*this)[i]); }))
402  {
403  found.push_back((*this)[i]);
404  }
405  return found;
406  }
407 
410  template <class Predicate, class VariantMap>
411  int applyIf(Predicate p, const VariantMap &newValues, bool skipEqualValues = false)
412  {
413  int count = 0;
414  for (auto &value : *this)
415  {
416  if (p(value) && !value.apply(newValues, skipEqualValues).isEmpty()) { count++; }
417  }
418  return count;
419  }
420 
427  template <class K1, class V1, class VariantMap>
428  int applyIf(K1 key1, V1 value1, const VariantMap &newValues, bool skipEqualValues = false)
429  {
430  return applyIf(swift::misc::predicates::MemberEqual(key1, value1), newValues, skipEqualValues);
431  }
432 
435  int remove(const T &object)
436  {
437  const auto newEnd = std::remove(begin(), end(), object);
438  const auto count = std::distance(newEnd, end());
439  erase(newEnd, end());
440  return count;
441  }
442 
445  template <class Predicate>
446  int removeIf(Predicate p)
447  {
448  const auto newEnd = std::remove_if(begin(), end(), p);
449  const auto count = std::distance(newEnd, end());
450  erase(newEnd, end());
451  return count;
452  }
453 
455  template <class K0, class V0, class... KeysValues>
456  int removeIf(K0 k0, V0 v0, KeysValues... keysValues)
457  {
458  // using-declaration doesn't play nicely with injected template names
459  return CSequence::CContainerBase::removeIf(k0, v0, keysValues...);
460  }
461 
464  int removeIfIn(const CSequence &other)
465  {
466  return removeIf([&other](const T &v) { return other.contains(v); });
467  }
468 
471  void removeIfInSubset(const CSequence &other)
472  {
473  erase(swift::misc::removeIfIn(begin(), end(), other.begin(), other.end()), end());
474  }
475 
478  int replace(const T &original, const T &replacement)
479  {
480  int count = 0;
481  for (auto &element : *this)
482  {
483  if (element == original)
484  {
485  element = replacement;
486  count++;
487  }
488  }
489  return count;
490  }
491 
494  template <class Predicate>
495  int replaceIf(Predicate p, const T &replacement)
496  {
497  int count = 0;
498  for (auto &element : *this)
499  {
500  if (p(element))
501  {
502  element = replacement;
503  count++;
504  }
505  }
506  return count;
507  }
508 
514  template <class K1, class V1>
515  int replaceIf(K1 key1, V1 value1, const T &replacement)
516  {
517  return replaceIf(swift::misc::predicates::MemberEqual(key1, value1), replacement);
518  }
519 
521  void replaceOrAdd(const T &original, const T &replacement)
522  {
523  if (this->contains(original)) { replace(original, replacement); }
524  else { push_back(replacement); }
525  }
526 
528  void replaceOrAdd(const T &replacement) { this->replaceOrAdd(replacement, replacement); }
529 
531  void replaceOrAdd(const CSequence<T> &replacements)
532  {
533  for (const T &replacement : replacements) { this->replaceOrAdd(replacement, replacement); }
534  }
535 
540  template <class K1, class V1>
541  void replaceOrAdd(K1 key1, V1 value1, const T &replacement)
542  {
543  if (this->contains(key1, value1)) { replaceIf(key1, value1, replacement); }
544  else { push_back(replacement); }
545  }
546 
548  void reverse() { std::reverse(begin(), end()); }
549 
551  Q_REQUIRED_RESULT CSequence reversed() const
552  {
553  CSequence result = *this;
554  result.reverse();
555  return result;
556  }
557 
559  template <class Predicate>
560  void sort(Predicate p)
561  {
562  QVector<T> temp;
563  temp.reserve(size());
564  for (int i :
565  private_ns::sortIndices(size(), [&p, this](int a, int b) { return p((*this)[a], (*this)[b]); }))
566  {
567  temp.push_back(std::move((*this)[i]));
568  }
569  m_impl = std::move(temp);
570  }
571 
575  template <class K1, class... Keys>
576  void sortBy(K1 key1, Keys... keys)
577  {
579  }
580 
582  template <class Predicate>
583  Q_REQUIRED_RESULT CSequence sorted(Predicate p) const
584  {
585  CSequence result = *this;
586  result.sort(p);
587  return result;
588  }
589 
593  template <class K1, class... Keys>
594  CSequence sortedBy(K1 key1, Keys... keys) const
595  {
596  return sorted(swift::misc::predicates::MemberLess(key1, keys...));
597  }
598 
600  template <class Predicate>
601  void partiallySort(size_type n, Predicate p)
602  {
603  std::partial_sort(begin(), begin() + std::min(n, size()), end(), p);
604  }
605 
610  template <class K1, class... Keys>
611  void partiallySortBy(size_type n, K1 key1, Keys... keys)
612  {
614  }
615 
617  template <class Predicate>
618  Q_REQUIRED_RESULT CSequence partiallySorted(size_type n, Predicate p) const
619  {
620  CSequence result = *this;
621  result.partiallySort(n, p);
622  return result;
623  }
624 
629  template <class K1, class... Keys>
630  CSequence partiallySortedBy(size_type n, K1 key1, Keys... keys) const
631  {
632  return partiallySorted(n, swift::misc::predicates::MemberLess(key1, keys...));
633  }
634 
637  template <class U, class Key0, class... Keys>
638  bool unorderedEqualsByKeys(const U &other, Key0 k0, Keys... keys) const
639  {
640  if (equalPointers(this, &other)) { return true; }
641  if (size() != other.size()) { return false; }
642  return sorted(k0, keys...).equalsByKeys(other.sorted(k0, keys...));
643  }
644 
646  template <class Predicate>
647  auto separate(Predicate p) const -> QMap<decltype(p(std::declval<T>())), CSequence>
648  {
650  auto copy = *this;
651  std::stable_sort(copy.begin(), copy.end(), [p](const T &a, const T &b) { return p(a) < p(b); });
652  for (auto it = copy.cbegin(); it != copy.cend();)
653  {
654  auto mid = std::adjacent_find(it, copy.cend(), [p](const T &a, const T &b) { return p(a) != p(b); });
655  result.insert(p(*it), makeRange(it, mid));
656  it = mid;
657  }
658  return result;
659  }
660 
662  template <class Key>
664  {
665  return separateBy([k](const T &v) { return std::invoke(k, v); });
666  }
667 
669  void detach() { m_impl.detach(); }
670 
672  friend bool operator==(const CSequence &a, const CSequence &b) { return a.m_impl == b.m_impl; }
673 
675  friend bool operator!=(const CSequence &a, const CSequence &b) { return a.m_impl != b.m_impl; }
676 
678  friend bool operator<(const CSequence &a, const CSequence &b) { return a.m_impl < b.m_impl; }
679 
681  friend bool operator>(const CSequence &a, const CSequence &b) { return a.m_impl > b.m_impl; }
682 
684  friend bool operator<=(const CSequence &a, const CSequence &b) { return a.m_impl <= b.m_impl; }
685 
687  friend bool operator>=(const CSequence &a, const CSequence &b) { return a.m_impl >= b.m_impl; }
688 
690  void marshalToDataStream(QDataStream &stream) const { stream << m_impl; }
691 
693  void unmarshalFromDataStream(QDataStream &stream) { stream >> m_impl; }
694 
695  private:
696  QList<T> m_impl;
697  };
698 } // namespace swift::misc
699 
700 Q_DECLARE_SEQUENTIAL_CONTAINER_METATYPE(swift::misc::CSequence)
701 
702 #endif // SWIFT_MISC_SEQUENCE_H
Base class for CCollection and CSequence adding mutating operations and CValueObject facility on top ...
Definition: containerbase.h:65
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:135
static bool equalPointers(const T *a, const U *b)
Efficiently compare addresses of two objects. Return false if types are not compatible.
Definition: range.h:166
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:190
const_iterator end() const
Begin and end iterators.
Definition: range.h:213
const_iterator begin() const
Begin and end iterators.
Definition: range.h:211
Generic sequential container with value semantics.
Definition: sequence.h:86
T value_type
STL compatilibty.
Definition: sequence.h:92
ptrdiff_t difference_type
STL compatibility.
Definition: sequence.h:119
void push_front(const CSequence &other)
Inserts all elements from another sequence at the beginning of this sequence.
Definition: sequence.h:311
const T * const_pointer
STL compatibility.
Definition: sequence.h:104
iterator erase(iterator pos)
Remove the element pointed to by the given iterator.
Definition: sequence.h:382
void push_back(T &&value)
Move-appends an element at the end of the sequence.
Definition: sequence.h:330
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:428
int removeIf(K0 k0, V0 v0, KeysValues... keysValues)
Remove elements matching some particular key/value pair(s).
Definition: sequence.h:456
CSequence sortedBy(K1 key1, Keys... keys) const
Return a copy sorted by some particular key(s).
Definition: sequence.h:594
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:681
int replaceIf(K1 key1, V1 value1, const T &replacement)
Replace elements matching a particular key/value pair.
Definition: sequence.h:515
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:576
void push_front(T &&value)
Move-insert as first element.
Definition: sequence.h:333
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:618
void pop_back()
Removes an element at the end of the sequence.
Definition: sequence.h:367
~CSequence()=default
Destructor.
T & reference
STL compatibility.
Definition: sequence.h:95
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:687
void unmarshalFromDataStream(QDataStream &stream)
Unmarshal a value from a QDataStream.
Definition: sequence.h:693
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:611
int replace(const T &original, const T &replacement)
Replace elements matching the given element with a replacement.
Definition: sequence.h:478
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:495
const_reference frontOrDefault() const
Access the first element, or a default-initialized value if the sequence is empty.
Definition: sequence.h:239
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:398
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:521
iterator erase(iterator it1, iterator it2)
Remove the range of elements between two iterators.
Definition: sequence.h:386
reverse_iterator rbegin()
Returns iterator at the beginning of the reversed sequence.
Definition: sequence.h:181
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:392
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:336
QVector< T >::const_reverse_iterator const_reverse_iterator
STL compatibility.
Definition: sequence.h:113
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:340
CSequence partiallySortedBy(size_type n, K1 key1, Keys... keys) const
Return a copy partially sorted by some particular key(s).
Definition: sequence.h:630
QVector< T > toVector() &&
Copy of internal vector.
Definition: sequence.h:160
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:638
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:583
void removeIfInSubset(const CSequence &other)
Remove all elements if they are in other.
Definition: sequence.h:471
bool empty() const
Returns true if the sequence is empty.
Definition: sequence.h:282
CSequence(CSequence &&other)=default
Move constructor.
value_type backOrDefault(value_type def) const
Access the last element, or a default value if the sequence is empty.
Definition: sequence.h:270
QVector< T > toVector() const &
Copy of internal vector.
Definition: sequence.h:157
int size_type
STL compatibility.
Definition: sequence.h:122
friend bool operator<(const CSequence &a, const CSequence &b)
Less than operator.
Definition: sequence.h:678
QVector< T >::reverse_iterator reverse_iterator
STL compatibility.
Definition: sequence.h:116
iterator insert(iterator before, T &&value)
Moves an element into the sequence.
Definition: sequence.h:302
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:647
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:672
int removeIf(Predicate p)
Remove elements for which a given predicate returns true.
Definition: sequence.h:446
void push_back(const T &value)
Appends an element at the end of the sequence.
Definition: sequence.h:305
const_reference back() const
Access the last element.
Definition: sequence.h:256
CSequence & operator=(const CSequence &other)=default
Copy assignment.
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:684
friend bool operator!=(const CSequence &a, const CSequence &b)
Not equals operator.
Definition: sequence.h:675
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:690
QVector< T >::iterator iterator
STL compatibility.
Definition: sequence.h:110
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:601
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:359
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:411
QVector< T >::const_iterator const_iterator
STL compatibility.
Definition: sequence.h:107
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:314
T key_type
STL compatibility.
Definition: sequence.h:89
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:389
void push_front(const T &value)
Insert as first element.
Definition: sequence.h:308
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:344
Q_REQUIRED_RESULT CSequence reversed() const
Reversed order.
Definition: sequence.h:551
void reverse()
In-place reverse.
Definition: sequence.h:548
int remove(const T &object)
Remove all elements equal to the given object, if it is contained.
Definition: sequence.h:435
CSequence & operator=(CSequence &&other)=default
Move assignment.
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:541
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:528
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:464
void push_backMaxElements(const T &value, int maxElements)
Insert as last element by keep maxElements.
Definition: sequence.h:322
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:298
void replaceOrAdd(const CSequence< T > &replacements)
Replace or add given elements.
Definition: sequence.h:531
CSequence join(const CSequence &other) const
Concatenates two sequences and returns the result.
Definition: sequence.h:350
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:663
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
T * pointer
STL compatibility.
Definition: sequence.h:101
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:374
const T & const_reference
STL compatibility.
Definition: sequence.h:98
void sort(Predicate p)
In-place sort by a given comparator predicate.
Definition: sequence.h:560
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:316
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
#define SWIFT_NO_INLINE
Prevent function inlining.
#define SWIFT_MISC_EXPORT
Export a class or function from the library.