Index: src/vector.h |
diff --git a/src/vector.h b/src/vector.h |
index d022fde3a5bb25d88b7fba5e9ca4ae375e94d20b..4f3128b9185cd42d21e439913a967c79753cb6f5 100644 |
--- a/src/vector.h |
+++ b/src/vector.h |
@@ -69,24 +69,30 @@ class Vector { |
return Vector<T>(result, length_); |
} |
- void Sort(int (*cmp)(const T*, const T*), size_t s, size_t l) { |
- std::sort(start() + s, start() + s + l, RawComparer(cmp)); |
+ template <typename CompareFunction> |
+ void Sort(CompareFunction cmp, size_t s, size_t l) { |
+ std::sort(start() + s, start() + s + l, RawComparer<CompareFunction>(cmp)); |
} |
- void Sort(int (*cmp)(const T*, const T*)) { |
- std::sort(start(), start() + length(), RawComparer(cmp)); |
+ template <typename CompareFunction> |
+ void Sort(CompareFunction cmp) { |
+ std::sort(start(), start() + length(), RawComparer<CompareFunction>(cmp)); |
} |
void Sort() { |
std::sort(start(), start() + length()); |
} |
- void StableSort(int (*cmp)(const T*, const T*), size_t s, size_t l) { |
- std::stable_sort(start() + s, start() + s + l, RawComparer(cmp)); |
+ template <typename CompareFunction> |
+ void StableSort(CompareFunction cmp, size_t s, size_t l) { |
+ std::stable_sort(start() + s, start() + s + l, |
+ RawComparer<CompareFunction>(cmp)); |
} |
- void StableSort(int (*cmp)(const T*, const T*)) { |
- std::stable_sort(start(), start() + length(), RawComparer(cmp)); |
+ template <typename CompareFunction> |
+ void StableSort(CompareFunction cmp) { |
+ std::stable_sort(start(), start() + length(), |
+ RawComparer<CompareFunction>(cmp)); |
} |
void StableSort() { std::stable_sort(start(), start() + length()); } |
@@ -136,15 +142,16 @@ class Vector { |
T* start_; |
int length_; |
+ template <typename CookedComparer> |
class RawComparer { |
public: |
- explicit RawComparer(int (*cmp)(const T*, const T*)) : cmp_(cmp) {} |
+ explicit RawComparer(CookedComparer cmp) : cmp_(cmp) {} |
bool operator()(const T& a, const T& b) { |
return cmp_(&a, &b) < 0; |
} |
private: |
- int (*cmp_)(const T*, const T*); |
+ CookedComparer cmp_; |
}; |
}; |