diff --git a/octa/algorithm.h b/octa/algorithm.h index 02c7f37..1aba246 100644 --- a/octa/algorithm.h +++ b/octa/algorithm.h @@ -10,6 +10,18 @@ #include "octa/range.h" namespace octa { + template + R partition(R range, U pred) { + R ret = range; + for (; !range.empty(); range.pop_first()) { + if (pred(range.first())) { + swap(range.first(), ret.first()); + ret.pop_first(); + } + } + return ret; + } + template void insertion_sort(R range, C compare) { size_t rlen = range.length(); @@ -28,7 +40,6 @@ namespace octa { insertion_sort(range, Less::value>()); } - template void sort(R range, C compare) { insertion_sort(range, compare); diff --git a/octa/utility.h b/octa/utility.h index e937e32..f81a2ed 100644 --- a/octa/utility.h +++ b/octa/utility.h @@ -38,17 +38,6 @@ namespace std { namespace octa { template using InitializerList = std::initializer_list; - template void swap(T &a, T &b) { - T c(move(a)); - a = move(b); - b = move(c); - } - template void swap(T (&a)[N], T (&b)[N]) { - for (size_t i = 0; i < N; ++i) { - swap(a[i], b[i]); - } - } - /* aliased in traits.h later */ namespace internal { template struct RemoveReference { typedef T type; }; @@ -153,6 +142,17 @@ namespace octa { internal::MemFn mem_fn(R T:: *ptr) { return internal::MemFn(ptr); } + + template void swap(T &a, T &b) { + T c(move(a)); + a = move(b); + b = move(c); + } + template void swap(T (&a)[N], T (&b)[N]) { + for (size_t i = 0; i < N; ++i) { + swap(a[i], b[i]); + } + } } #endif \ No newline at end of file