1 #pragma once
2 
3 namespace mapbox {
4 namespace geometry {
5 namespace wagyu {
6 
7 template <typename It, class Compare, class MethodOnSwap>
bubble_sort(It begin,It end,Compare c,MethodOnSwap m)8 void bubble_sort(It begin, It end, Compare c, MethodOnSwap m) {
9     if (begin == end) {
10         return;
11     }
12     bool modified = false;
13     auto last = end - 1;
14     do {
15         modified = false;
16         for (auto itr = begin; itr != last; ++itr) {
17             auto next = std::next(itr);
18             if (!c(*itr, *next)) {
19                 m(*itr, *next);
20                 std::iter_swap(itr, next);
21                 modified = true;
22             }
23         }
24     } while (modified);
25 }
26 }
27 }
28 }
29