Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Updated std::min and std::max
  • Loading branch information
brynne8 committed Jun 21, 2014
1 parent a3e4b59 commit 21d76a4
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions include/algorithm
Expand Up @@ -7,10 +7,23 @@ namespace std {

// until our template function resolution is a little more
// sophisticated, we just use specialized versions.
int min(int a, int b) { return a > b ? b : a; }
int max(int a, int b) { return a > b ? a : b; }
double min(double a, double b) { return a > b ? b : a; }
double max(double a, double b) { return a > b ? a : b; }
template <class T>
const T& min(const T& a, const T& b) {
return !(b<a)?a:b;
}
template <class T>
const T& max(const T& a, const T& b) {
return (a<b)?b:a;
}
// version 2
template <class T, class BPr>
const T& min(const T& a, const T& b, BPr comp) {
return !comp(b,a)?a:b;
}
template <class T, class BPr>
const T& max(const T& a, const T& b, BPr comp) {
return comp(a,b)?b:a;
}

template <class In, class Pr>
bool all_of(In i1, In i2, Pr pred)
Expand Down

0 comments on commit 21d76a4

Please sign in to comment.