aboutsummaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorJohannes Schickel2008-01-28 22:05:23 +0000
committerJohannes Schickel2008-01-28 22:05:23 +0000
commitd8e1f5a060654e1abd8ff9fc69b34320383e59f3 (patch)
tree0149a8aa9173bdd57714a0aaf5f31c6fb1b86b54 /common
parent7aac83007d53aa2d398a9a1e639f8d29064819a1 (diff)
downloadscummvm-rg350-d8e1f5a060654e1abd8ff9fc69b34320383e59f3.tar.gz
scummvm-rg350-d8e1f5a060654e1abd8ff9fc69b34320383e59f3.tar.bz2
scummvm-rg350-d8e1f5a060654e1abd8ff9fc69b34320383e59f3.zip
- make Common::sort supporting a function object to compare two entries instead of operator <
- adapt parallaction to use the new Common::sort function svn-id: r30692
Diffstat (limited to 'common')
-rw-r--r--common/algorithm.h21
1 files changed, 21 insertions, 0 deletions
diff --git a/common/algorithm.h b/common/algorithm.h
index e2ee653fca..beae34245f 100644
--- a/common/algorithm.h
+++ b/common/algorithm.h
@@ -131,6 +131,27 @@ void sort(T first, T last) {
}
}
+// Using this with: Common::Less from common/func.h
+// will give the same results as the function above.
+template<class T, class StrictWeakOrdering>
+void sort(T first, T last, StrictWeakOrdering comp) {
+ if (first == last)
+ return;
+
+ // Simple selection sort
+ T i(first);
+ for (; i != last; ++i) {
+ T minElem(i);
+ T j(i);
+ ++j;
+ for (; j != last; ++j)
+ if (comp(*j, *minElem))
+ minElem = j;
+ if (minElem != i)
+ SWAP(*minElem, *i);
+ }
+}
+
} // end of namespace Common
#endif