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:
Orgad Shaneh
2016-08-03 22:55:07 +03:00
committed by Orgad Shaneh
parent d8e94afb51
commit a23e0692b4
2 changed files with 45 additions and 0 deletions

View File

@@ -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
/////////////////