CMR  1.3.0
comparators.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 namespace tu
4 {
5 
12  struct is_non_zero
13  {
19  _valid(false)
20  {
21 
22  }
23 
30  void operator()(int value)
31  {
32  if (value != 0)
33  _valid = true;
34  }
35 
42  bool operator()()
43  {
44  bool result = _valid;
45  _valid = false;
46  return result;
47  }
48 
49  private:
50  bool _valid;
51  };
52 
59  struct is_all_ones
60  {
66  _valid(true)
67  {
68 
69  }
70 
77  void operator()(int value)
78  {
79  if (value == 0)
80  _valid = false;
81  }
82 
89  bool operator()()
90  {
91  bool result = _valid;
92  _valid = true;
93  return result;
94  }
95 
96  private:
97  bool _valid;
98  };
99 
106  template <typename T, typename Less = std::less <T> >
107  struct vector_less
108  {
116  vector_less(const std::vector <T>& data, Less less = Less()) :
117  _less(less), data_(data)
118  {
119 
120  }
121 
130  bool operator ()(size_t i, size_t j)
131  {
132  return _less(data_[i], data_[j]);
133  }
134 
135  private:
136  Less _less;
137  const std::vector <T>& data_;
138  };
139 
140 } /* namespace tu */
Definition: algorithm.hpp:14
Definition: comparators.hpp:60
void operator()(int value)
Definition: comparators.hpp:77
is_all_ones()
Definition: comparators.hpp:65
bool operator()()
Definition: comparators.hpp:89
Definition: comparators.hpp:13
bool operator()()
Definition: comparators.hpp:42
is_non_zero()
Definition: comparators.hpp:18
void operator()(int value)
Definition: comparators.hpp:30
Definition: comparators.hpp:108
bool operator()(size_t i, size_t j)
Definition: comparators.hpp:130
vector_less(const std::vector< T > &data, Less less=Less())
Definition: comparators.hpp:116