17#ifndef LIB_ALGORITHM_H_ 
   18#define LIB_ALGORITHM_H_ 
   24#define ROUNDUP(x, y) (((x) + (y) - 1) / (y)) 
   26#define ELEMENTS(a) (sizeof(a) / sizeof(a[0])) 
   30template <
class C, 
class T>
 
   31inline bool contains(C &c, 
const T &val) {
 
   32    return std::find(c.begin(), c.end(), val) != c.end();
 
   35template <
class C, 
class Pred>
 
   36inline bool contains_if(C &c, Pred pred) {
 
   37    return std::find_if(c.begin(), c.end(), pred) != c.end();
 
   40template <
class C, 
class Pred>
 
   41inline void erase_if(C &c, Pred pred) {
 
   42    for (
auto it = c.begin(); it != c.end();) {
 
   50template <
class C, 
class Pred>
 
   51inline void remove_if(C &c, Pred pred) {
 
   52    c.erase(std::remove_if(c.begin(), c.end(), pred), c.end());
 
   55template <
class C, 
class T>
 
   56inline typename C::iterator find(C &c, 
const T &val) {
 
   57    return std::find(c.begin(), c.end(), val);
 
   60using std::max_element;
 
   61using std::min_element;
 
   64inline typename C::const_iterator min_element(
const C &c) {
 
   65    return min_element(c.begin(), c.end());
 
   67template <
class C, 
class Compare>
 
   68inline typename C::const_iterator min_element(
const C &c, Compare comp) {
 
   69    return min_element(c.begin(), c.end(), comp);
 
   73inline typename C::const_iterator max_element(
const C &c) {
 
   74    return max_element(c.begin(), c.end());
 
   76template <
class C, 
class Compare>
 
   77inline typename C::const_iterator max_element(
const C &c, Compare comp) {
 
   78    return max_element(c.begin(), c.end(), comp);
 
   81template <
class Iter, 
class Fn>
 
   82inline Fn for_each(std::pair<Iter, Iter> range, Fn fn) {
 
   83    return std::for_each(range.first, range.second, fn);
 
   87Iter begin(std::pair<Iter, Iter> pr) {
 
   91Iter end(std::pair<Iter, Iter> pr) {