diff --git a/octa/algorithm.h b/octa/algorithm.h index 406ba48..71bba2c 100644 --- a/octa/algorithm.h +++ b/octa/algorithm.h @@ -40,6 +40,15 @@ namespace octa { insertion_sort(range, Less::value>()); } + namespace internal { + template + struct UnaryCompare { + T val; + U comp; + bool operator()(const T &v) const { return comp(v, val); } + }; + } + template void quicksort(R range, C compare) { if (range.length() <= 10) { @@ -48,8 +57,8 @@ namespace octa { } typename RangeTraits::reference p = range[range.length() / 2]; swap(p, range.last()); - R r = partition(range, [p, compare](decltype(p) v) { - return compare(v, p); + R r = partition(range, internal::UnaryCompare{ + p, compare }); R l = range.slice(0, range.length() - r.length()); swap(r.first(), r.last());