aboutsummaryrefslogtreecommitdiff
path: root/common/func.h
diff options
context:
space:
mode:
authorMax Horn2006-04-04 23:55:47 +0000
committerMax Horn2006-04-04 23:55:47 +0000
commitbec09d30945c7dc143dc4ccd5e2fba1dcaccaac1 (patch)
treeae23245d53ee0b48082405b7d9409854423a3610 /common/func.h
parent66d8b85463da60f0b88c3f7d6068df502d940546 (diff)
downloadscummvm-rg350-bec09d30945c7dc143dc4ccd5e2fba1dcaccaac1.tar.gz
scummvm-rg350-bec09d30945c7dc143dc4ccd5e2fba1dcaccaac1.tar.bz2
scummvm-rg350-bec09d30945c7dc143dc4ccd5e2fba1dcaccaac1.zip
Turned FSList::sort into a generic function which can be applied to anything which implements comparable iterators (like Array, List, or plain C arrays)
svn-id: r21617
Diffstat (limited to 'common/func.h')
-rw-r--r--common/func.h22
1 files changed, 22 insertions, 0 deletions
diff --git a/common/func.h b/common/func.h
index 10c80e66f5..e2cd20fdb3 100644
--- a/common/func.h
+++ b/common/func.h
@@ -62,6 +62,28 @@ GENERATE_TRIVIAL_HASH_FUNCTOR(unsigned long);
#undef GENERATE_TRIVIAL_HASH_FUNCTOR
+// Simple sort function, modelled after std::sort.
+// Use it like this: sort(container.begin(), container.end()).
+// Also work on plain old int arrays etc.
+template <typename T>
+void sort(T first, T last) {
+ if (first == last)
+ return;
+
+ // Simple selection sort
+ T i(first);
+ for (; i != last; ++i) {
+ T min(i);
+ T j(i);
+ ++j;
+ for (; j != last; ++j)
+ if (*j < *min)
+ min = j;
+ if (min != i)
+ SWAP(*min, *i);
+ }
+}
+
} // End of namespace Common