31 #ifndef COMMON_STD_ALGORITHM_H 32 #define COMMON_STD_ALGORITHM_H 34 #include "common/algorithm.h" 35 #include "common/util.h" 39 template<
typename T>
inline T abs(T x) {
42 template<
typename T>
inline T min(T a, T b) {
45 template<
typename T>
inline T max(T a, T b) {
48 template<
typename T>
inline T clip(T v, T amin, T amax) {
49 return CLIP(v, amin, amax);
51 template<
typename T>
inline T sqrt(T x) {
54 template<
typename T>
inline void swap(T &a, T &b) {
58 template<
class In,
class Value>
59 In
fill(In first, In last,
const Value &val) {
63 template<
typename T,
class StrictWeakOrdering>
64 void sort(T first, T last, StrictWeakOrdering comp) {
69 void sort(T *first, T *last) {
74 void sort(T first, T last) {
78 template<
class In,
class T>
79 In
find(In first, In last,
const T &v) {
84 T unique(T first, T last) {
86 for (pos = first + 1; pos < last; ++pos) {
88 for (T existingPos = first; existingPos < last; ++existingPos) {
89 if (*pos == *existingPos) {
91 while (pos < (last - 1)) {
106 template<
class ForwardIt,
class T>
107 ForwardIt lower_bound(ForwardIt first, ForwardIt last,
const T &value) {
108 for (ForwardIt it = first; it < last; ++it) {
116 template<
class ForwardIt,
class T>
117 ForwardIt upper_bound(ForwardIt first, ForwardIt last,
const T &value) {
118 for (ForwardIt it = first; it < last; ++it) {
126 template<
class ForwardIt,
class T,
class Compare>
127 ForwardIt upper_bound(ForwardIt first, ForwardIt last,
const T &value, Compare comp) {
128 for (ForwardIt it = first; it < last; ++it) {
129 if (comp(value, *it))
136 template<
class ForwardIt>
137 ForwardIt next(ForwardIt it,
int n = 1) {
139 while (n > 0) { ++it2; --n; }
140 while (n < 0) { --it2; ++n; }
144 template<
class B
idirIt>
145 BidirIt prev(BidirIt it,
int n = 1) {
147 while (n > 0) { --it2; --n; }
148 while (n < 0) { ++it2; ++n; }
void sort(T first, T last)
Definition: algorithm.h:378
In find(In first, In last, const T &v)
Definition: algorithm.h:225
void SWAP(T &a, T &b)
Definition: util.h:84
T CLIP(T v, T amin, T amax)
Definition: util.h:67
In fill(In first, In last, const Value &val)
Definition: algorithm.h:214
signed char * fill(signed char *first, signed char *last, Value val)
Definition: algorithm.h:168
T MIN(T a, T b)
Definition: util.h:61
T MAX(T a, T b)
Definition: util.h:64
T ABS(T x)
Definition: util.h:58
void sort(T first, T last, StrictWeakOrdering comp)
Definition: algorithm.h:349
Definition: algorithm.h:37