twinkle icon indicating copy to clipboard operation
twinkle copied to clipboard

qt5+: Replace `qSort()` with `std::sort()`

Open fbriere opened this issue 3 years ago • 1 comments

qSort() (along with a good portion of QtAlgorithms) was deprecated in Qt 5.2, in favor of using STL algorithms instead.

Note that std::sort is not an exact drop-in replacement for qSort, due to the following differences:

  • qSort can take a Qt container as argument
  • qSort will automatically use qLess<T> if defined
  • std::sort requires the comparison functor to honour Strict Weak Ordering

The first two points don't apply to us; we never call qSort with a container, nor do we ever specialize qLess<T> anywhere.

As for the last point, since AddressTableModel::sort() eventually delegates its job to the < and > operators (defaulting to false), it can never return true for both a comparison and its opposite, thus satisfying Strict Weak Ordering.

fbriere avatar Sep 01 '22 17:09 fbriere

Note: This was motivated by the fact that qSort() is no longer available in Qt 6 (#297).

fbriere avatar Sep 01 '22 17:09 fbriere