entt  2.7.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 {
35  template<typename It, typename Compare = std::less<>, typename... Args>
36  void operator()(It first, It last, Compare compare = Compare{}, Args &&... args) const {
37  std::sort(std::forward<Args>(args)..., std::move(first), std::move(last), std::move(compare));
38  }
39 };
40 
41 
43 struct InsertionSort {
55  template<typename It, typename Compare = std::less<>>
56  void operator()(It first, It last, Compare compare = Compare{}) const {
57  auto it = first + 1;
58 
59  while(it != last) {
60  auto value = *it;
61  auto pre = it;
62 
63  while(pre != first && compare(value, *(pre-1))) {
64  *pre = *(pre-1);
65  --pre;
66  }
67 
68  *pre = value;
69  ++it;
70  }
71  }
72 };
73 
74 
75 }
76 
77 
78 #endif // ENTT_CORE_ALGORITHM_HPP
EnTT default namespace.
Definition: algorithm.hpp:10
Function object for performing insertion sort.
Definition: algorithm.hpp:43
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:56
void operator()(It first, It last, Compare compare=Compare{}, Args &&... args) const
Sorts the element in a range.
Definition: algorithm.hpp:36