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