#ifndef _library__minmax__hpp__included__ #define _library__minmax__hpp__included__ #include /** * Return minimum of a and b. */ template T min(T a, T b) { return (a < b) ? a : b; } /** * Return maximum of a and b. */ template T max(T a, T b) { return (a < b) ? b : a; } /** * Clip v to [a,b]. */ template T clip(T v, T a, T b) { return (v < a) ? a : ((v > b) ? b : v); } template class pair_assign_helper { public: pair_assign_helper(T& _a, U& _b) : a(_a), b(_b) {} const std::pair& operator=(const std::pair& r) { a = r.first; b = r.second; return r; } private: T& a; U& b; }; /** * Create a rvalue from components of pair. */ template pair_assign_helper rpair(T& a, U& b) { return pair_assign_helper(a, b); } #endif