Cypress  1.0
C++ Spiking Neural Network Simulation Framework
optional.hpp
Go to the documentation of this file.
1 /*
2  * Cypress -- C++ Spiking Neural Network Simulation Framework
3  * Copyright (C) 2016 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 #ifndef CYPRESS_UTIL_OPTIONAL
20 #define CYPRESS_UTIL_OPTIONAL
21 
22 #include <limits>
23 
24 namespace cypress {
25 
26 template<typename T>
27 struct NumericPolicy {
28  static constexpr T empty() {return std::numeric_limits<T>::max();}
29  static constexpr bool is_empty(const T &v) {return v == empty();}
30 };
31 
32 template<typename T, typename Policy = NumericPolicy<T>>
33 class Optional {
34 private:
35  T m_value;
36 
37 public:
38  constexpr Optional() : m_value(Policy::empty()) {}
39  constexpr Optional(T v) : m_value(v) {}
40 
41  constexpr bool valid() const {return !Policy::is_empty(m_value); }
42  constexpr T value() const {return m_value; }
43 };
44 
45 }
46 
47 #endif /* CYPRESS_UTIL_OPTIONAL */
constexpr bool valid() const
Definition: optional.hpp:41
static constexpr bool is_empty(const T &v)
Definition: optional.hpp:29
static constexpr T empty()
Definition: optional.hpp:28
constexpr Optional()
Definition: optional.hpp:38
constexpr Optional(T v)
Definition: optional.hpp:39
Definition: optional.hpp:33
Definition: optional.hpp:27
Definition: brainscales_lib.hpp:39
constexpr T value() const
Definition: optional.hpp:42