2012-02-23 16:48:56 +02:00
|
|
|
#ifndef _library__minmax__hpp__included__
|
|
|
|
#define _library__minmax__hpp__included__
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return minimum of a and b.
|
|
|
|
*/
|
|
|
|
template<typename T> T min(T a, T b)
|
|
|
|
{
|
|
|
|
return (a < b) ? a : b;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return maximum of a and b.
|
|
|
|
*/
|
|
|
|
template<typename T> T max(T a, T b)
|
|
|
|
{
|
|
|
|
return (a < b) ? b : a;
|
|
|
|
}
|
|
|
|
|
2013-12-24 20:29:31 +02:00
|
|
|
/**
|
|
|
|
* Clip v to [a,b].
|
|
|
|
*/
|
|
|
|
template<typename T> T clip(T v, T a, T b)
|
|
|
|
{
|
|
|
|
return (v < a) ? a : ((v > b) ? b : v);
|
|
|
|
}
|
|
|
|
|
2014-02-17 16:18:36 +02:00
|
|
|
template<typename T, typename U>
|
|
|
|
class pair_assign_helper
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
pair_assign_helper(T& _a, U& _b) : a(_a), b(_b) {}
|
|
|
|
const std::pair<T, U>& operator=(const std::pair<T, U>& r)
|
|
|
|
{
|
|
|
|
a = r.first;
|
|
|
|
b = r.second;
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
T& a;
|
|
|
|
U& b;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a rvalue from components of pair.
|
|
|
|
*/
|
|
|
|
template<typename T, typename U>
|
|
|
|
pair_assign_helper<T, U> rpair(T& a, U& b)
|
|
|
|
{
|
|
|
|
return pair_assign_helper<T, U>(a, b);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-09-08 19:44:45 +03:00
|
|
|
|
2012-02-23 16:48:56 +02:00
|
|
|
#endif
|