forked from qt-creator/qt-creator
Utils: Use std::stable_sort() in Utils::sort()
Potentially makes for a more consistent user experience, and does fix some CppTools test failures on macOS. Change-Id: I5bfd7a2460248450ad92259956598532fb7fb8ee Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -997,13 +997,13 @@ Container<T> static_container_cast(const Container<Base> &container)
|
|||||||
template <typename Container>
|
template <typename Container>
|
||||||
inline void sort(Container &container)
|
inline void sort(Container &container)
|
||||||
{
|
{
|
||||||
std::sort(std::begin(container), std::end(container));
|
std::stable_sort(std::begin(container), std::end(container));
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Container, typename Predicate>
|
template <typename Container, typename Predicate>
|
||||||
inline void sort(Container &container, Predicate p)
|
inline void sort(Container &container, Predicate p)
|
||||||
{
|
{
|
||||||
std::sort(std::begin(container), std::end(container), p);
|
std::stable_sort(std::begin(container), std::end(container), p);
|
||||||
}
|
}
|
||||||
|
|
||||||
// pointer to member
|
// pointer to member
|
||||||
@@ -1012,7 +1012,7 @@ inline void sort(Container &container, R S::*member)
|
|||||||
{
|
{
|
||||||
auto f = std::mem_fn(member);
|
auto f = std::mem_fn(member);
|
||||||
using const_ref = typename Container::const_reference;
|
using const_ref = typename Container::const_reference;
|
||||||
std::sort(std::begin(container), std::end(container),
|
std::stable_sort(std::begin(container), std::end(container),
|
||||||
[&f](const_ref a, const_ref b) {
|
[&f](const_ref a, const_ref b) {
|
||||||
return f(a) < f(b);
|
return f(a) < f(b);
|
||||||
});
|
});
|
||||||
@@ -1024,7 +1024,7 @@ inline void sort(Container &container, R (S::*function)() const)
|
|||||||
{
|
{
|
||||||
auto f = std::mem_fn(function);
|
auto f = std::mem_fn(function);
|
||||||
using const_ref = typename Container::const_reference;
|
using const_ref = typename Container::const_reference;
|
||||||
std::sort(std::begin(container), std::end(container),
|
std::stable_sort(std::begin(container), std::end(container),
|
||||||
[&f](const_ref a, const_ref b) {
|
[&f](const_ref a, const_ref b) {
|
||||||
return f(a) < f(b);
|
return f(a) < f(b);
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user