Obsolete Members for <QtAlgorithms>

The following members of class <QtAlgorithms> are obsolete. They are provided to keep old source code working. We strongly advise against using them in new code.

Functions

(obsolete) RandomAccessIterator qBinaryFind(RandomAccessIterator begin, RandomAccessIterator end, const T &value)
(obsolete) RandomAccessIterator qBinaryFind(RandomAccessIterator begin, RandomAccessIterator end, const T &value, LessThan lessThan)
(obsolete) typename Container::const_iterator qBinaryFind(const Container &container, const T &value)
(obsolete) int qGreater()
(obsolete) int qLess()
(obsolete) RandomAccessIterator qLowerBound(RandomAccessIterator begin, RandomAccessIterator end, const T &value)
(obsolete) RandomAccessIterator qLowerBound(RandomAccessIterator begin, RandomAccessIterator end, const T &value, LessThan lessThan)
(obsolete) typename Container::const_iterator qLowerBound(const Container &container, const T &value)
(obsolete) void qSort(RandomAccessIterator begin, RandomAccessIterator end)
(obsolete) void qSort(RandomAccessIterator begin, RandomAccessIterator end, LessThan lessThan)
(obsolete) void qSort(Container &container)
(obsolete) void qStableSort(RandomAccessIterator begin, RandomAccessIterator end)
(obsolete) void qStableSort(RandomAccessIterator begin, RandomAccessIterator end, LessThan lessThan)
(obsolete) void qStableSort(Container &container)
(obsolete) void qSwap(T &var1, T &var2)
(obsolete) RandomAccessIterator qUpperBound(RandomAccessIterator begin, RandomAccessIterator end, const T &value)
(obsolete) RandomAccessIterator qUpperBound(RandomAccessIterator begin, RandomAccessIterator end, const T &value, LessThan lessThan)
(obsolete) typename Container::const_iterator qUpperBound(const Container &container, const T &value)

Function Documentation

RandomAccessIterator qBinaryFind(RandomAccessIterator begin, RandomAccessIterator end, const T &value)

This function is obsolete. It is provided to keep old source code working. We strongly advise against using it in new code.

Use std::binary_search or std::lower_bound instead.

Performs a binary search of the range [begin, end) and returns the position of an occurrence of value. If there are no occurrences of value, returns end.

The items in the range [begin, end) must be sorted in ascending order; see qSort().

If there are many occurrences of the same value, any one of them could be returned. Use qLowerBound() or qUpperBound() if you need finer control.

Example:


  QVector<int> vect;
  vect << 3 << 3 << 6 << 6 << 6 << 8;

  QVector<int>::iterator i =
          qBinaryFind(vect.begin(), vect.end(), 6);
  // i == vect.begin() + 2 (or 3 or 4)

This function requires the item type (in the example above, QString) to implement operator<().

See also qLowerBound(), qUpperBound(), and random access iterators.

RandomAccessIterator qBinaryFind(RandomAccessIterator begin, RandomAccessIterator end, const T &value, LessThan lessThan)

This function is obsolete. It is provided to keep old source code working. We strongly advise against using it in new code.

This is an overloaded function.

Use std::binary_search or std::lower_bound instead.

Uses the lessThan function instead of operator<() to compare the items.

Note that the items in the range must be sorted according to the order specified by the lessThan object.

typename Container::const_iterator qBinaryFind(const Container &container, const T &value)

This function is obsolete. It is provided to keep old source code working. We strongly advise against using it in new code.

This is an overloaded function.

Use std::binary_search or std::lower_bound instead.

This is the same as qBinaryFind(container.begin(), container.end(), value);

int qGreater()

This function is obsolete. It is provided to keep old source code working. We strongly advise against using it in new code.

Use std::greater instead.

Returns a functional object, or functor, that can be passed to qSort() or qStableSort().

Example:


  QList<int> list;
  list << 33 << 12 << 68 << 6 << 12;
  qSort(list.begin(), list.end(), qGreater<int>());
  // list: [ 68, 33, 12, 12, 6 ]

See also qLess<T>().

int qLess()

This function is obsolete. It is provided to keep old source code working. We strongly advise against using it in new code.

Use std::less instead.

Returns a functional object, or functor, that can be passed to qSort() or qStableSort().

Example:


  QList<int> list;
  list << 33 << 12 << 68 << 6 << 12;
  qSort(list.begin(), list.end(), qLess<int>());
  // list: [ 6, 12, 12, 33, 68 ]

See also qGreater<T>().

RandomAccessIterator qLowerBound(RandomAccessIterator begin, RandomAccessIterator end, const T &value)

This function is obsolete. It is provided to keep old source code working. We strongly advise against using it in new code.

Use std::lower_bound instead.

Performs a binary search of the range [begin, end) and returns the position of the first occurrence of value. If no such item is found, returns the position where it should be inserted.

The items in the range [begin, end) must be sorted in ascending order; see qSort().

Example:


  QList<int> list;
  list << 3 << 3 << 6 << 6 << 6 << 8;

  QList<int>::iterator i = qLowerBound(list.begin(), list.end(), 5);
  list.insert(i, 5);
  // list: [ 3, 3, 5, 6, 6, 6, 8 ]

  i = qLowerBound(list.begin(), list.end(), 12);
  list.insert(i, 12);
  // list: [ 3, 3, 5, 6, 6, 6, 8, 12 ]

This function requires the item type (in the example above, int) to implement operator<().

qLowerBound() can be used in conjunction with qUpperBound() to iterate over all occurrences of the same value:


  QVector<int> vect;
  vect << 3 << 3 << 6 << 6 << 6 << 8;
  QVector<int>::iterator begin6 =
          qLowerBound(vect.begin(), vect.end(), 6);
  QVector<int>::iterator end6 =
          qUpperBound(begin6, vect.end(), 6);

  QVector<int>::iterator i = begin6;
  while (i != end6) {
      *i = 7;
      ++i;
  }
  // vect: [ 3, 3, 7, 7, 7, 8 ]

See also qUpperBound() and qBinaryFind().

RandomAccessIterator qLowerBound(RandomAccessIterator begin, RandomAccessIterator end, const T &value, LessThan lessThan)

This function is obsolete. It is provided to keep old source code working. We strongly advise against using it in new code.

This is an overloaded function.

Use std::lower_bound instead.

Uses the lessThan function instead of operator<() to compare the items.

Note that the items in the range must be sorted according to the order specified by the lessThan object.

typename Container::const_iterator qLowerBound(const Container &container, const T &value)

This function is obsolete. It is provided to keep old source code working. We strongly advise against using it in new code.

This is an overloaded function.

Use std::lower_bound instead.

For read-only iteration over containers, this function is broadly equivalent to qLowerBound(container.begin(), container.end(), value). However, since it returns a const iterator, you cannot use it to modify the container; for example, to insert items.

void qSort(RandomAccessIterator begin, RandomAccessIterator end)

This function is obsolete. It is provided to keep old source code working. We strongly advise against using it in new code.

Use std::sort instead.

Sorts the items in range [begin, end) in ascending order using the quicksort algorithm.

Example:


  QList<int> list;
  list << 33 << 12 << 68 << 6 << 12;
  qSort(list.begin(), list.end());
  // list: [ 6, 12, 12, 33, 68 ]

The sort algorithm is efficient on large data sets. It operates in linear-logarithmic time, O(n log n).

This function requires the item type (in the example above, int) to implement operator<().

If neither of the two items is "less than" the other, the items are taken to be equal. It is then undefined which one of the two items will appear before the other after the sort.

See also qStableSort() and random access iterators.

void qSort(RandomAccessIterator begin, RandomAccessIterator end, LessThan lessThan)

This function is obsolete. It is provided to keep old source code working. We strongly advise against using it in new code.

This is an overloaded function.

Use std::sort instead.

Uses the lessThan function instead of operator<() to compare the items.

For example, here's how to sort the strings in a QStringList in case-insensitive alphabetical order:


  bool caseInsensitiveLessThan(const QString &s1, const QString &s2)
  {
      return s1.toLower() < s2.toLower();
  }

  int doSomething()
  {
      QStringList list;
      list << "AlPha" << "beTA" << "gamma" << "DELTA";
      qSort(list.begin(), list.end(), caseInsensitiveLessThan);
      // list: [ "AlPha", "beTA", "DELTA", "gamma" ]
  }

To sort values in reverse order, pass qGreater<T>() as the lessThan parameter. For example:


  QList<int> list;
  list << 33 << 12 << 68 << 6 << 12;
  qSort(list.begin(), list.end(), qGreater<int>());
  // list: [ 68, 33, 12, 12, 6 ]

If neither of the two items is "less than" the other, the items are taken to be equal. It is then undefined which one of the two items will appear before the other after the sort.

An alternative to using qSort() is to put the items to sort in a QMap, using the sort key as the QMap key. This is often more convenient than defining a lessThan function. For example, the following code shows how to sort a list of strings case insensitively using QMap:


  QStringList list;
  list << "AlPha" << "beTA" << "gamma" << "DELTA";

  QMap<QString, QString> map;
  foreach (const QString &str, list)
      map.insert(str.toLower(), str);

  list = map.values();

See also QMap.

void qSort(Container &container)

This function is obsolete. It is provided to keep old source code working. We strongly advise against using it in new code.

This is an overloaded function.

Use std::sort instead.

This is the same as qSort(container.begin(), container.end());

void qStableSort(RandomAccessIterator begin, RandomAccessIterator end)

This function is obsolete. It is provided to keep old source code working. We strongly advise against using it in new code.

Use std::stable_sort instead.

Sorts the items in range [begin, end) in ascending order using a stable sorting algorithm.

If neither of the two items is "less than" the other, the items are taken to be equal. The item that appeared before the other in the original container will still appear first after the sort. This property is often useful when sorting user-visible data.

Example:


  QList<int> list;
  list << 33 << 12 << 68 << 6 << 12;
  qStableSort(list.begin(), list.end());
  // list: [ 6, 12, 12, 33, 68 ]

The sort algorithm is efficient on large data sets. It operates in linear-logarithmic time, O(n log n).

This function requires the item type (in the example above, int) to implement operator<().

See also qSort() and random access iterators.

void qStableSort(RandomAccessIterator begin, RandomAccessIterator end, LessThan lessThan)

This function is obsolete. It is provided to keep old source code working. We strongly advise against using it in new code.

This is an overloaded function.

Use std::stable_sort instead.

Uses the lessThan function instead of operator<() to compare the items.

For example, here's how to sort the strings in a QStringList in case-insensitive alphabetical order:


  bool caseInsensitiveLessThan(const QString &s1, const QString &s2)
  {
      return s1.toLower() < s2.toLower();
  }

  int doSomething()
  {
      QStringList list;
      list << "AlPha" << "beTA" << "gamma" << "DELTA";
      qStableSort(list.begin(), list.end(), caseInsensitiveLessThan);
      // list: [ "AlPha", "beTA", "DELTA", "gamma" ]
  }

Note that earlier versions of Qt allowed using a lessThan function that took its arguments by non-const reference. From 4.3 and on this is no longer possible, the arguments has to be passed by const reference or value.

To sort values in reverse order, pass qGreater<T>() as the lessThan parameter. For example:


  QList<int> list;
  list << 33 << 12 << 68 << 6 << 12;
  qStableSort(list.begin(), list.end(), qGreater<int>());
  // list: [ 68, 33, 12, 12, 6 ]

If neither of the two items is "less than" the other, the items are taken to be equal. The item that appeared before the other in the original container will still appear first after the sort. This property is often useful when sorting user-visible data.

void qStableSort(Container &container)

This function is obsolete. It is provided to keep old source code working. We strongly advise against using it in new code.

This is an overloaded function.

Use std::stable_sort instead.

This is the same as qStableSort(container.begin(), container.end());

void qSwap(T &var1, T &var2)

This function is obsolete. It is provided to keep old source code working. We strongly advise against using it in new code.

Use std::swap instead.

Exchanges the values of variables var1 and var2.

Example:


  double pi = 3.14;
  double e = 2.71;

  qSwap(pi, e);
  // pi == 2.71, e == 3.14

RandomAccessIterator qUpperBound(RandomAccessIterator begin, RandomAccessIterator end, const T &value)

This function is obsolete. It is provided to keep old source code working. We strongly advise against using it in new code.

Use std::upper_bound instead.

Performs a binary search of the range [begin, end) and returns the position of the one-past-the-last occurrence of value. If no such item is found, returns the position where the item should be inserted.

The items in the range [begin, end) must be sorted in ascending order; see qSort().

Example:


  QList<int> list;
  list << 3 << 3 << 6 << 6 << 6 << 8;

  QList<int>::iterator i = qUpperBound(list.begin(), list.end(), 5);
  list.insert(i, 5);
  // list: [ 3, 3, 5, 6, 6, 6, 8 ]

  i = qUpperBound(list.begin(), list.end(), 12);
  list.insert(i, 12);
  // list: [ 3, 3, 5, 6, 6, 6, 8, 12 ]

This function requires the item type (in the example above, int) to implement operator<().

qUpperBound() can be used in conjunction with qLowerBound() to iterate over all occurrences of the same value:


  QVector<int> vect;
  vect << 3 << 3 << 6 << 6 << 6 << 8;
  QVector<int>::iterator begin6 =
          qLowerBound(vect.begin(), vect.end(), 6);
  QVector<int>::iterator end6 =
          qUpperBound(vect.begin(), vect.end(), 6);

  QVector<int>::iterator i = begin6;
  while (i != end6) {
      *i = 7;
      ++i;
  }
  // vect: [ 3, 3, 7, 7, 7, 8 ]

See also qLowerBound() and qBinaryFind().

RandomAccessIterator qUpperBound(RandomAccessIterator begin, RandomAccessIterator end, const T &value, LessThan lessThan)

This function is obsolete. It is provided to keep old source code working. We strongly advise against using it in new code.

This is an overloaded function.

Use std::upper_bound instead.

Uses the lessThan function instead of operator<() to compare the items.

Note that the items in the range must be sorted according to the order specified by the lessThan object.

typename Container::const_iterator qUpperBound(const Container &container, const T &value)

This function is obsolete. It is provided to keep old source code working. We strongly advise against using it in new code.

This is an overloaded function.

Use std::upper_bound instead.

This is the same as qUpperBound(container.begin(), container.end(), value);