8#ifndef LIB_ALGORITHM_H_
9#define LIB_ALGORITHM_H_
15#define ROUNDUP(x, y) (((x) + (y) - 1) / (y))
17#define ELEMENTS(a) (sizeof(a) / sizeof(a[0]))
22template <
class C,
class T>
23inline bool contains(C &c,
const T &val) {
24 return std::find(c.begin(), c.end(), val) != c.end();
27template <
class C,
class Pred>
28inline bool contains_if(C &c, Pred pred) {
29 return std::find_if(c.begin(), c.end(), pred) != c.end();
32template <
class C,
class Pred>
33inline void erase_if(C &c, Pred pred) {
34 for (
auto it = c.begin(); it != c.end();) {
42template <
class C,
class Pred>
43inline void remove_if(C &c, Pred pred) {
44 c.erase(std::remove_if(c.begin(), c.end(), pred), c.end());
47template <
class C,
class T>
48inline typename C::iterator find(C &c,
const T &val) {
49 return std::find(c.begin(), c.end(), val);
52using std::max_element;
53using std::min_element;
56inline typename C::const_iterator min_element(
const C &c) {
57 return min_element(c.begin(), c.end());
59template <
class C,
class Compare>
60inline typename C::const_iterator min_element(
const C &c, Compare comp) {
61 return min_element(c.begin(), c.end(), comp);
65inline typename C::const_iterator max_element(
const C &c) {
66 return max_element(c.begin(), c.end());
68template <
class C,
class Compare>
69inline typename C::const_iterator max_element(
const C &c, Compare comp) {
70 return max_element(c.begin(), c.end(), comp);
73template <
class Iter,
class Fn>
74inline Fn for_each(std::pair<Iter, Iter> range, Fn fn) {
75 return std::for_each(range.first, range.second, fn);
79Iter begin(std::pair<Iter, Iter> pr) {
83Iter end(std::pair<Iter, Iter> pr) {
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:13