forked from qt-creator/qt-creator
Utils: Introduce sort variants for member and member function
Change-Id: Iff29f2c55a08e85de7f0ff4e431f326e351e5305 Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
committed by
Orgad Shaneh
parent
d8e94afb51
commit
a23e0692b4
@@ -384,6 +384,24 @@ inline void sort(Container &c, Predicate p)
|
||||
std::sort(c.begin(), c.end(), p);
|
||||
}
|
||||
|
||||
// pointer to member
|
||||
template <typename Container, typename R, typename S>
|
||||
inline void sort(Container &c, R S::*member)
|
||||
{
|
||||
std::sort(c.begin(), c.end(), [member](const S &a, const S &b) {
|
||||
return a.*member < b.*member;
|
||||
});
|
||||
}
|
||||
|
||||
// pointer to member function
|
||||
template <typename Container, typename R, typename S>
|
||||
inline void sort(Container &c, R (S::*function)() const)
|
||||
{
|
||||
std::sort(c.begin(), c.end(), [function](const S &a, const S &b) {
|
||||
return (a.*function)() < (b.*function)();
|
||||
});
|
||||
}
|
||||
|
||||
//////////////////
|
||||
// reverseForeach
|
||||
/////////////////
|
||||
|
||||
Reference in New Issue
Block a user