Cypress  1.0
C++ Spiking Neural Network Simulation Framework
comperator.hpp
Go to the documentation of this file.
1 /*
2  * CppNAM -- C++ Neural Associative Memory Simulator
3  * Copyright (C) 2016 Christoph Jenzen, Andreas Stöckel
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #pragma once
20 
21 #ifndef CPPNAM_UTIL_COMPARISON_HPP
22 #define CPPNAM_UTIL_COMPARISON_HPP
23 
24 #include <cstdint>
25 
26 namespace cypress {
33 template <typename T>
34 struct Comperator {
39  template <int Threshold, typename F>
44  const F &f;
45 
49  const int res;
50 
57  explicit ComperatorFunctor(const F &f, int res = 0) : f(f), res(res) {}
58 
67  const T &t2) const
68  {
69  if (res == 0) {
70  return make_comperator<Threshold, F>(f, f(t1, t2));
71  }
72  return make_comperator<Threshold, F>(f, res);
73  }
74 
78  bool operator()() const { return res >= Threshold; }
79  };
80 
81  template <int Threshold, typename F>
83  int res = 0)
84  {
86  }
87 
88  static auto smaller(const T &t1, const T &t2)
89  {
90  return make_comperator<1>([](const T &t1, const T &t2) {
91  return (t1 < t2) ? 1 : ((t1 == t2) ? 0 : -1);
92  })(t1, t2);
93  }
94 
95  static auto smaller_equals(const T &t1, const T &t2)
96  {
97  return make_comperator<0>([](const T &t1, const T &t2) {
98  return (t1 < t2) ? 1 : ((t1 == t2) ? 0 : -1);
99  })(t1, t2);
100  }
101 
102  static auto larger(const T &t1, const T &t2)
103  {
104  return make_comperator<1>([](const T &t1, const T &t2) {
105  return (t1 > t2) ? 1 : ((t1 == t2) ? 0 : -1);
106  })(t1, t2);
107  }
108 
109  static auto larger_equals(const T &t1, const T &t2)
110  {
111  return make_comperator<0>([](const T &t1, const T &t2) {
112  return (t1 > t2) ? 1 : ((t1 == t2) ? 0 : -1);
113  })(t1, t2);
114  }
115 
116  static auto equals(const T &t1, const T &t2)
117  {
118  return make_comperator<0>([](const T &t1, const T &t2) {
119  return (t1 == t2) ? 0 : -1;
120  })(t1, t2);
121  }
122 
123  static auto inequal(const T &t1, const T &t2)
124  {
125  return make_comperator<1>([](const T &t1, const T &t2) {
126  return (t1 != t2) ? 1 : 0;
127  })(t1, t2);
128  }
129 };
130 }
131 
132 #endif /* CPPNAM_UTIL_COMPARISON_HPP */
static auto smaller_equals(const T &t1, const T &t2)
Definition: comperator.hpp:95
static auto larger(const T &t1, const T &t2)
Definition: comperator.hpp:102
const int res
Definition: comperator.hpp:49
static auto equals(const T &t1, const T &t2)
Definition: comperator.hpp:116
bool operator()() const
Definition: comperator.hpp:78
static ComperatorFunctor< Threshold, F > make_comperator(const F &f, int res=0)
Definition: comperator.hpp:82
static auto smaller(const T &t1, const T &t2)
Definition: comperator.hpp:88
ComperatorFunctor(const F &f, int res=0)
Definition: comperator.hpp:57
const F & f
Definition: comperator.hpp:44
Definition: comperator.hpp:40
Definition: brainscales_lib.hpp:39
ComperatorFunctor< Threshold, F > operator()(const T &t1, const T &t2) const
Definition: comperator.hpp:66
Definition: comperator.hpp:34
static auto inequal(const T &t1, const T &t2)
Definition: comperator.hpp:123
static auto larger_equals(const T &t1, const T &t2)
Definition: comperator.hpp:109