entt  2.6.1
algorithm.hpp
1 #ifndef ENTT_CORE_ALGORITHM_HPP
2 #define ENTT_CORE_ALGORITHM_HPP
3 
4 
5 #include <functional>
6 #include <algorithm>
7 #include <utility>
8 
9 
10 namespace entt {
11 
12 
21 struct StdSort {
33  template<typename It, typename Compare = std::less<>>
34  void operator()(It first, It last, Compare compare = Compare{}) const {
35  std::sort(std::move(first), std::move(last), std::move(compare));
36  }
37 };
38 
39 
41 struct InsertionSort {
53  template<typename It, typename Compare = std::less<>>
54  void operator()(It first, It last, Compare compare = Compare{}) const {
55  auto it = first + 1;
56 
57  while(it != last) {
58  auto value = *it;
59  auto pre = it;
60 
61  while(pre != first && compare(value, *(pre-1))) {
62  *pre = *(pre-1);
63  --pre;
64  }
65 
66  *pre = value;
67  ++it;
68  }
69  }
70 };
71 
72 
73 }
74 
75 
76 #endif // ENTT_CORE_ALGORITHM_HPP
EnTT default namespace.
Definition: algorithm.hpp:10
void operator()(It first, It last, Compare compare=Compare{}) const
Sorts the element in a range.
Definition: algorithm.hpp:34
Function object for performing insertion sort.
Definition: algorithm.hpp:41
Function object to wrap std::sort in a class type.
Definition: algorithm.hpp:21
void operator()(It first, It last, Compare compare=Compare{}) const
Sorts the element in a range.
Definition: algorithm.hpp:54