Device interface library for multiple platforms including Mbed.
Dependents: DeepCover Embedded Security in IoT MaximInterface MAXREFDES155#
Maxim Interface is a library framework focused on providing flexible and expressive hardware interfaces. Both communication interfaces such as I2C and 1-Wire and device interfaces such as DS18B20 are supported. Modern C++ concepts are used extensively while keeping compatibility with C++98/C++03 and requiring no external dependencies. The embedded-friendly design does not depend on exceptions or RTTI.
The full version of the project is hosted on GitLab: https://gitlab.com/iabenz/MaximInterface
MaximInterfaceCore/Optional.hpp@12:7eb41621ba22, 2020-05-29 (annotated)
- Committer:
- IanBenzMaxim
- Date:
- Fri May 29 16:19:22 2020 -0500
- Revision:
- 12:7eb41621ba22
- Parent:
- 8:5ea891c7d1a1
Updated to version 2.2.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
IanBenzMaxim | 7:9cd16581b578 | 1 | /******************************************************************************* |
IanBenzMaxim | 8:5ea891c7d1a1 | 2 | * Copyright (C) Maxim Integrated Products, Inc., All Rights Reserved. |
IanBenzMaxim | 7:9cd16581b578 | 3 | * |
IanBenzMaxim | 7:9cd16581b578 | 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
IanBenzMaxim | 7:9cd16581b578 | 5 | * copy of this software and associated documentation files (the "Software"), |
IanBenzMaxim | 7:9cd16581b578 | 6 | * to deal in the Software without restriction, including without limitation |
IanBenzMaxim | 7:9cd16581b578 | 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
IanBenzMaxim | 7:9cd16581b578 | 8 | * and/or sell copies of the Software, and to permit persons to whom the |
IanBenzMaxim | 7:9cd16581b578 | 9 | * Software is furnished to do so, subject to the following conditions: |
IanBenzMaxim | 7:9cd16581b578 | 10 | * |
IanBenzMaxim | 7:9cd16581b578 | 11 | * The above copyright notice and this permission notice shall be included |
IanBenzMaxim | 7:9cd16581b578 | 12 | * in all copies or substantial portions of the Software. |
IanBenzMaxim | 7:9cd16581b578 | 13 | * |
IanBenzMaxim | 7:9cd16581b578 | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
IanBenzMaxim | 7:9cd16581b578 | 15 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
IanBenzMaxim | 7:9cd16581b578 | 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
IanBenzMaxim | 7:9cd16581b578 | 17 | * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES |
IanBenzMaxim | 7:9cd16581b578 | 18 | * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
IanBenzMaxim | 7:9cd16581b578 | 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
IanBenzMaxim | 7:9cd16581b578 | 20 | * OTHER DEALINGS IN THE SOFTWARE. |
IanBenzMaxim | 7:9cd16581b578 | 21 | * |
IanBenzMaxim | 7:9cd16581b578 | 22 | * Except as contained in this notice, the name of Maxim Integrated |
IanBenzMaxim | 7:9cd16581b578 | 23 | * Products, Inc. shall not be used except as stated in the Maxim Integrated |
IanBenzMaxim | 7:9cd16581b578 | 24 | * Products, Inc. Branding Policy. |
IanBenzMaxim | 7:9cd16581b578 | 25 | * |
IanBenzMaxim | 7:9cd16581b578 | 26 | * The mere transfer of this software does not imply any licenses |
IanBenzMaxim | 7:9cd16581b578 | 27 | * of trade secrets, proprietary technology, copyrights, patents, |
IanBenzMaxim | 7:9cd16581b578 | 28 | * trademarks, maskwork rights, or any other form of intellectual |
IanBenzMaxim | 7:9cd16581b578 | 29 | * property whatsoever. Maxim Integrated Products, Inc. retains all |
IanBenzMaxim | 7:9cd16581b578 | 30 | * ownership rights. |
IanBenzMaxim | 7:9cd16581b578 | 31 | *******************************************************************************/ |
IanBenzMaxim | 7:9cd16581b578 | 32 | |
IanBenzMaxim | 8:5ea891c7d1a1 | 33 | #ifndef MaximInterfaceCore_Optional_hpp |
IanBenzMaxim | 8:5ea891c7d1a1 | 34 | #define MaximInterfaceCore_Optional_hpp |
IanBenzMaxim | 7:9cd16581b578 | 35 | |
IanBenzMaxim | 7:9cd16581b578 | 36 | #include "None.hpp" |
IanBenzMaxim | 7:9cd16581b578 | 37 | #include "SafeBool.hpp" |
IanBenzMaxim | 7:9cd16581b578 | 38 | |
IanBenzMaxim | 7:9cd16581b578 | 39 | // Include for std::swap. |
IanBenzMaxim | 7:9cd16581b578 | 40 | #include <algorithm> |
IanBenzMaxim | 7:9cd16581b578 | 41 | #include <utility> |
IanBenzMaxim | 7:9cd16581b578 | 42 | |
IanBenzMaxim | 7:9cd16581b578 | 43 | namespace MaximInterfaceCore { |
IanBenzMaxim | 7:9cd16581b578 | 44 | |
IanBenzMaxim | 8:5ea891c7d1a1 | 45 | /// @brief %Optional value container similar to std::optional. |
IanBenzMaxim | 7:9cd16581b578 | 46 | /// @details |
IanBenzMaxim | 7:9cd16581b578 | 47 | /// To prevent the need for aligned storage, this implementation imposes that |
IanBenzMaxim | 7:9cd16581b578 | 48 | /// types must be DefaultConstructible, CopyConstructible, and CopyAssignable. |
IanBenzMaxim | 7:9cd16581b578 | 49 | /// No exceptions are thrown when accessing a valueless Optional. |
IanBenzMaxim | 7:9cd16581b578 | 50 | template <typename T> class Optional { |
IanBenzMaxim | 7:9cd16581b578 | 51 | public: |
IanBenzMaxim | 7:9cd16581b578 | 52 | typedef T value_type; |
IanBenzMaxim | 7:9cd16581b578 | 53 | |
IanBenzMaxim | 7:9cd16581b578 | 54 | Optional() : value_(), hasValue_(false) {} |
IanBenzMaxim | 7:9cd16581b578 | 55 | |
IanBenzMaxim | 7:9cd16581b578 | 56 | Optional(None) : value_(), hasValue_(false) {} |
IanBenzMaxim | 7:9cd16581b578 | 57 | |
IanBenzMaxim | 7:9cd16581b578 | 58 | Optional(const T & value) : value_(value), hasValue_(true) {} |
IanBenzMaxim | 7:9cd16581b578 | 59 | |
IanBenzMaxim | 7:9cd16581b578 | 60 | template <typename U> |
IanBenzMaxim | 7:9cd16581b578 | 61 | explicit Optional(const Optional<U> & other) |
IanBenzMaxim | 7:9cd16581b578 | 62 | : value_(other.value()), hasValue_(other.hasValue()) {} |
IanBenzMaxim | 7:9cd16581b578 | 63 | |
IanBenzMaxim | 7:9cd16581b578 | 64 | Optional & operator=(None) { |
IanBenzMaxim | 7:9cd16581b578 | 65 | reset(); |
IanBenzMaxim | 7:9cd16581b578 | 66 | return *this; |
IanBenzMaxim | 7:9cd16581b578 | 67 | } |
IanBenzMaxim | 7:9cd16581b578 | 68 | |
IanBenzMaxim | 8:5ea891c7d1a1 | 69 | Optional & operator=(const T & value) { |
IanBenzMaxim | 8:5ea891c7d1a1 | 70 | value_ = value; |
IanBenzMaxim | 8:5ea891c7d1a1 | 71 | hasValue_ = true; |
IanBenzMaxim | 8:5ea891c7d1a1 | 72 | return *this; |
IanBenzMaxim | 8:5ea891c7d1a1 | 73 | } |
IanBenzMaxim | 8:5ea891c7d1a1 | 74 | |
IanBenzMaxim | 7:9cd16581b578 | 75 | template <typename U> Optional & operator=(const Optional<U> & other) { |
IanBenzMaxim | 8:5ea891c7d1a1 | 76 | assign(other); |
IanBenzMaxim | 8:5ea891c7d1a1 | 77 | return *this; |
IanBenzMaxim | 8:5ea891c7d1a1 | 78 | } |
IanBenzMaxim | 8:5ea891c7d1a1 | 79 | |
IanBenzMaxim | 8:5ea891c7d1a1 | 80 | Optional & operator=(const Optional & other) { |
IanBenzMaxim | 8:5ea891c7d1a1 | 81 | assign(other); |
IanBenzMaxim | 7:9cd16581b578 | 82 | return *this; |
IanBenzMaxim | 7:9cd16581b578 | 83 | } |
IanBenzMaxim | 7:9cd16581b578 | 84 | |
IanBenzMaxim | 7:9cd16581b578 | 85 | bool hasValue() const { return hasValue_; } |
IanBenzMaxim | 7:9cd16581b578 | 86 | |
IanBenzMaxim | 7:9cd16581b578 | 87 | operator SafeBool() const { return makeSafeBool(hasValue()); } |
IanBenzMaxim | 7:9cd16581b578 | 88 | |
IanBenzMaxim | 7:9cd16581b578 | 89 | const T & value() const { return value_; } |
IanBenzMaxim | 7:9cd16581b578 | 90 | |
IanBenzMaxim | 7:9cd16581b578 | 91 | T & value() { |
IanBenzMaxim | 7:9cd16581b578 | 92 | return const_cast<T &>(static_cast<const Optional &>(*this).value()); |
IanBenzMaxim | 7:9cd16581b578 | 93 | } |
IanBenzMaxim | 7:9cd16581b578 | 94 | |
IanBenzMaxim | 7:9cd16581b578 | 95 | const T & operator*() const { return value(); } |
IanBenzMaxim | 7:9cd16581b578 | 96 | |
IanBenzMaxim | 7:9cd16581b578 | 97 | T & operator*() { |
IanBenzMaxim | 7:9cd16581b578 | 98 | return const_cast<T &>(static_cast<const Optional &>(*this).operator*()); |
IanBenzMaxim | 7:9cd16581b578 | 99 | } |
IanBenzMaxim | 7:9cd16581b578 | 100 | |
IanBenzMaxim | 7:9cd16581b578 | 101 | const T * operator->() const { return &value(); } |
IanBenzMaxim | 7:9cd16581b578 | 102 | |
IanBenzMaxim | 7:9cd16581b578 | 103 | T * operator->() { |
IanBenzMaxim | 7:9cd16581b578 | 104 | return const_cast<T *>(static_cast<const Optional &>(*this).operator->()); |
IanBenzMaxim | 7:9cd16581b578 | 105 | } |
IanBenzMaxim | 7:9cd16581b578 | 106 | |
IanBenzMaxim | 7:9cd16581b578 | 107 | const T & valueOr(const T & defaultValue) const { |
IanBenzMaxim | 7:9cd16581b578 | 108 | return hasValue() ? value() : defaultValue; |
IanBenzMaxim | 7:9cd16581b578 | 109 | } |
IanBenzMaxim | 7:9cd16581b578 | 110 | |
IanBenzMaxim | 7:9cd16581b578 | 111 | void swap(Optional & other) { |
IanBenzMaxim | 7:9cd16581b578 | 112 | if (hasValue_ || other.hasValue_) { |
IanBenzMaxim | 7:9cd16581b578 | 113 | using std::swap; |
IanBenzMaxim | 7:9cd16581b578 | 114 | swap(value_, other.value_); |
IanBenzMaxim | 7:9cd16581b578 | 115 | swap(hasValue_, other.hasValue_); |
IanBenzMaxim | 7:9cd16581b578 | 116 | } |
IanBenzMaxim | 7:9cd16581b578 | 117 | } |
IanBenzMaxim | 7:9cd16581b578 | 118 | |
IanBenzMaxim | 7:9cd16581b578 | 119 | void reset() { |
IanBenzMaxim | 7:9cd16581b578 | 120 | if (hasValue_) { |
IanBenzMaxim | 7:9cd16581b578 | 121 | hasValue_ = false; |
IanBenzMaxim | 7:9cd16581b578 | 122 | value_ = T(); |
IanBenzMaxim | 7:9cd16581b578 | 123 | } |
IanBenzMaxim | 7:9cd16581b578 | 124 | } |
IanBenzMaxim | 7:9cd16581b578 | 125 | |
IanBenzMaxim | 7:9cd16581b578 | 126 | private: |
IanBenzMaxim | 8:5ea891c7d1a1 | 127 | template <typename U> void assign(const Optional<U> & other) { |
IanBenzMaxim | 8:5ea891c7d1a1 | 128 | if (hasValue_ || other.hasValue()) { |
IanBenzMaxim | 8:5ea891c7d1a1 | 129 | value_ = other.value(); |
IanBenzMaxim | 8:5ea891c7d1a1 | 130 | hasValue_ = other.hasValue(); |
IanBenzMaxim | 8:5ea891c7d1a1 | 131 | } |
IanBenzMaxim | 8:5ea891c7d1a1 | 132 | } |
IanBenzMaxim | 8:5ea891c7d1a1 | 133 | |
IanBenzMaxim | 7:9cd16581b578 | 134 | T value_; |
IanBenzMaxim | 7:9cd16581b578 | 135 | bool hasValue_; |
IanBenzMaxim | 7:9cd16581b578 | 136 | }; |
IanBenzMaxim | 7:9cd16581b578 | 137 | |
IanBenzMaxim | 7:9cd16581b578 | 138 | template <typename T> Optional<T> makeOptional(const T & value) { |
IanBenzMaxim | 7:9cd16581b578 | 139 | return value; |
IanBenzMaxim | 7:9cd16581b578 | 140 | } |
IanBenzMaxim | 7:9cd16581b578 | 141 | |
IanBenzMaxim | 7:9cd16581b578 | 142 | template <typename T> void swap(Optional<T> & lhs, Optional<T> & rhs) { |
IanBenzMaxim | 7:9cd16581b578 | 143 | lhs.swap(rhs); |
IanBenzMaxim | 7:9cd16581b578 | 144 | } |
IanBenzMaxim | 7:9cd16581b578 | 145 | |
IanBenzMaxim | 7:9cd16581b578 | 146 | template <typename T, typename U> |
IanBenzMaxim | 7:9cd16581b578 | 147 | bool operator==(const Optional<T> & lhs, const Optional<U> & rhs) { |
IanBenzMaxim | 7:9cd16581b578 | 148 | if (lhs.hasValue() != rhs.hasValue()) { |
IanBenzMaxim | 7:9cd16581b578 | 149 | return false; |
IanBenzMaxim | 7:9cd16581b578 | 150 | } |
IanBenzMaxim | 7:9cd16581b578 | 151 | if (!lhs.hasValue()) { |
IanBenzMaxim | 7:9cd16581b578 | 152 | return true; |
IanBenzMaxim | 7:9cd16581b578 | 153 | } |
IanBenzMaxim | 7:9cd16581b578 | 154 | return lhs.value() == rhs.value(); |
IanBenzMaxim | 7:9cd16581b578 | 155 | } |
IanBenzMaxim | 7:9cd16581b578 | 156 | |
IanBenzMaxim | 7:9cd16581b578 | 157 | template <typename T, typename U> |
IanBenzMaxim | 7:9cd16581b578 | 158 | bool operator!=(const Optional<T> & lhs, const Optional<U> & rhs) { |
IanBenzMaxim | 7:9cd16581b578 | 159 | if (lhs.hasValue() != rhs.hasValue()) { |
IanBenzMaxim | 7:9cd16581b578 | 160 | return true; |
IanBenzMaxim | 7:9cd16581b578 | 161 | } |
IanBenzMaxim | 7:9cd16581b578 | 162 | if (!lhs.hasValue()) { |
IanBenzMaxim | 7:9cd16581b578 | 163 | return false; |
IanBenzMaxim | 7:9cd16581b578 | 164 | } |
IanBenzMaxim | 7:9cd16581b578 | 165 | return lhs.value() != rhs.value(); |
IanBenzMaxim | 7:9cd16581b578 | 166 | } |
IanBenzMaxim | 7:9cd16581b578 | 167 | |
IanBenzMaxim | 7:9cd16581b578 | 168 | template <typename T, typename U> |
IanBenzMaxim | 7:9cd16581b578 | 169 | bool operator<(const Optional<T> & lhs, const Optional<U> & rhs) { |
IanBenzMaxim | 7:9cd16581b578 | 170 | if (!rhs.hasValue()) { |
IanBenzMaxim | 7:9cd16581b578 | 171 | return false; |
IanBenzMaxim | 7:9cd16581b578 | 172 | } |
IanBenzMaxim | 7:9cd16581b578 | 173 | if (!lhs.hasValue()) { |
IanBenzMaxim | 7:9cd16581b578 | 174 | return true; |
IanBenzMaxim | 7:9cd16581b578 | 175 | } |
IanBenzMaxim | 7:9cd16581b578 | 176 | return lhs.value() < rhs.value(); |
IanBenzMaxim | 7:9cd16581b578 | 177 | } |
IanBenzMaxim | 7:9cd16581b578 | 178 | |
IanBenzMaxim | 7:9cd16581b578 | 179 | template <typename T, typename U> |
IanBenzMaxim | 7:9cd16581b578 | 180 | bool operator<=(const Optional<T> & lhs, const Optional<U> & rhs) { |
IanBenzMaxim | 7:9cd16581b578 | 181 | if (!lhs.hasValue()) { |
IanBenzMaxim | 7:9cd16581b578 | 182 | return true; |
IanBenzMaxim | 7:9cd16581b578 | 183 | } |
IanBenzMaxim | 7:9cd16581b578 | 184 | if (!rhs.hasValue()) { |
IanBenzMaxim | 7:9cd16581b578 | 185 | return false; |
IanBenzMaxim | 7:9cd16581b578 | 186 | } |
IanBenzMaxim | 7:9cd16581b578 | 187 | return lhs.value() <= rhs.value(); |
IanBenzMaxim | 7:9cd16581b578 | 188 | } |
IanBenzMaxim | 7:9cd16581b578 | 189 | |
IanBenzMaxim | 7:9cd16581b578 | 190 | template <typename T, typename U> |
IanBenzMaxim | 7:9cd16581b578 | 191 | bool operator>(const Optional<T> & lhs, const Optional<U> & rhs) { |
IanBenzMaxim | 7:9cd16581b578 | 192 | if (!lhs.hasValue()) { |
IanBenzMaxim | 7:9cd16581b578 | 193 | return false; |
IanBenzMaxim | 7:9cd16581b578 | 194 | } |
IanBenzMaxim | 7:9cd16581b578 | 195 | if (!rhs.hasValue()) { |
IanBenzMaxim | 7:9cd16581b578 | 196 | return true; |
IanBenzMaxim | 7:9cd16581b578 | 197 | } |
IanBenzMaxim | 7:9cd16581b578 | 198 | return lhs.value() > rhs.value(); |
IanBenzMaxim | 7:9cd16581b578 | 199 | } |
IanBenzMaxim | 7:9cd16581b578 | 200 | |
IanBenzMaxim | 7:9cd16581b578 | 201 | template <typename T, typename U> |
IanBenzMaxim | 7:9cd16581b578 | 202 | bool operator>=(const Optional<T> & lhs, const Optional<U> & rhs) { |
IanBenzMaxim | 7:9cd16581b578 | 203 | if (!rhs.hasValue()) { |
IanBenzMaxim | 7:9cd16581b578 | 204 | return true; |
IanBenzMaxim | 7:9cd16581b578 | 205 | } |
IanBenzMaxim | 7:9cd16581b578 | 206 | if (!lhs.hasValue()) { |
IanBenzMaxim | 7:9cd16581b578 | 207 | return false; |
IanBenzMaxim | 7:9cd16581b578 | 208 | } |
IanBenzMaxim | 7:9cd16581b578 | 209 | return lhs.value() >= rhs.value(); |
IanBenzMaxim | 7:9cd16581b578 | 210 | } |
IanBenzMaxim | 7:9cd16581b578 | 211 | |
IanBenzMaxim | 7:9cd16581b578 | 212 | template <typename T> bool operator==(const Optional<T> & opt, None) { |
IanBenzMaxim | 7:9cd16581b578 | 213 | return !opt.hasValue(); |
IanBenzMaxim | 7:9cd16581b578 | 214 | } |
IanBenzMaxim | 7:9cd16581b578 | 215 | |
IanBenzMaxim | 7:9cd16581b578 | 216 | template <typename T> bool operator==(None, const Optional<T> & opt) { |
IanBenzMaxim | 7:9cd16581b578 | 217 | return operator==(opt, none); |
IanBenzMaxim | 7:9cd16581b578 | 218 | } |
IanBenzMaxim | 7:9cd16581b578 | 219 | |
IanBenzMaxim | 7:9cd16581b578 | 220 | template <typename T> bool operator!=(const Optional<T> & opt, None) { |
IanBenzMaxim | 7:9cd16581b578 | 221 | return !operator==(opt, none); |
IanBenzMaxim | 7:9cd16581b578 | 222 | } |
IanBenzMaxim | 7:9cd16581b578 | 223 | |
IanBenzMaxim | 7:9cd16581b578 | 224 | template <typename T> bool operator!=(None, const Optional<T> & opt) { |
IanBenzMaxim | 7:9cd16581b578 | 225 | return operator!=(opt, none); |
IanBenzMaxim | 7:9cd16581b578 | 226 | } |
IanBenzMaxim | 7:9cd16581b578 | 227 | |
IanBenzMaxim | 7:9cd16581b578 | 228 | template <typename T> bool operator<(const Optional<T> &, None) { |
IanBenzMaxim | 7:9cd16581b578 | 229 | return false; |
IanBenzMaxim | 7:9cd16581b578 | 230 | } |
IanBenzMaxim | 7:9cd16581b578 | 231 | |
IanBenzMaxim | 7:9cd16581b578 | 232 | template <typename T> bool operator<(None, const Optional<T> & opt) { |
IanBenzMaxim | 7:9cd16581b578 | 233 | return opt.hasValue(); |
IanBenzMaxim | 7:9cd16581b578 | 234 | } |
IanBenzMaxim | 7:9cd16581b578 | 235 | |
IanBenzMaxim | 7:9cd16581b578 | 236 | template <typename T> bool operator<=(const Optional<T> & opt, None) { |
IanBenzMaxim | 7:9cd16581b578 | 237 | return !operator>(opt, none); |
IanBenzMaxim | 7:9cd16581b578 | 238 | } |
IanBenzMaxim | 7:9cd16581b578 | 239 | |
IanBenzMaxim | 7:9cd16581b578 | 240 | template <typename T> bool operator<=(None, const Optional<T> & opt) { |
IanBenzMaxim | 7:9cd16581b578 | 241 | return !operator>(none, opt); |
IanBenzMaxim | 7:9cd16581b578 | 242 | } |
IanBenzMaxim | 7:9cd16581b578 | 243 | |
IanBenzMaxim | 7:9cd16581b578 | 244 | template <typename T> bool operator>(const Optional<T> & opt, None) { |
IanBenzMaxim | 7:9cd16581b578 | 245 | return operator<(none, opt); |
IanBenzMaxim | 7:9cd16581b578 | 246 | } |
IanBenzMaxim | 7:9cd16581b578 | 247 | |
IanBenzMaxim | 7:9cd16581b578 | 248 | template <typename T> bool operator>(None, const Optional<T> & opt) { |
IanBenzMaxim | 7:9cd16581b578 | 249 | return operator<(opt, none); |
IanBenzMaxim | 7:9cd16581b578 | 250 | } |
IanBenzMaxim | 7:9cd16581b578 | 251 | |
IanBenzMaxim | 7:9cd16581b578 | 252 | template <typename T> bool operator>=(const Optional<T> & opt, None) { |
IanBenzMaxim | 7:9cd16581b578 | 253 | return !operator<(opt, none); |
IanBenzMaxim | 7:9cd16581b578 | 254 | } |
IanBenzMaxim | 7:9cd16581b578 | 255 | |
IanBenzMaxim | 7:9cd16581b578 | 256 | template <typename T> bool operator>=(None, const Optional<T> & opt) { |
IanBenzMaxim | 7:9cd16581b578 | 257 | return !operator<(none, opt); |
IanBenzMaxim | 7:9cd16581b578 | 258 | } |
IanBenzMaxim | 7:9cd16581b578 | 259 | |
IanBenzMaxim | 7:9cd16581b578 | 260 | template <typename T, typename U> |
IanBenzMaxim | 7:9cd16581b578 | 261 | bool operator==(const Optional<T> & opt, const U & value) { |
IanBenzMaxim | 7:9cd16581b578 | 262 | return opt.hasValue() ? opt.value() == value : false; |
IanBenzMaxim | 7:9cd16581b578 | 263 | } |
IanBenzMaxim | 7:9cd16581b578 | 264 | |
IanBenzMaxim | 7:9cd16581b578 | 265 | template <typename T, typename U> |
IanBenzMaxim | 7:9cd16581b578 | 266 | bool operator==(const T & value, const Optional<U> & opt) { |
IanBenzMaxim | 7:9cd16581b578 | 267 | return operator==(opt, value); |
IanBenzMaxim | 7:9cd16581b578 | 268 | } |
IanBenzMaxim | 7:9cd16581b578 | 269 | |
IanBenzMaxim | 7:9cd16581b578 | 270 | template <typename T, typename U> |
IanBenzMaxim | 7:9cd16581b578 | 271 | bool operator!=(const Optional<T> & opt, const U & value) { |
IanBenzMaxim | 7:9cd16581b578 | 272 | return opt.hasValue() ? opt.value() != value : true; |
IanBenzMaxim | 7:9cd16581b578 | 273 | } |
IanBenzMaxim | 7:9cd16581b578 | 274 | |
IanBenzMaxim | 7:9cd16581b578 | 275 | template <typename T, typename U> |
IanBenzMaxim | 7:9cd16581b578 | 276 | bool operator!=(const T & value, const Optional<U> & opt) { |
IanBenzMaxim | 7:9cd16581b578 | 277 | return operator!=(opt, value); |
IanBenzMaxim | 7:9cd16581b578 | 278 | } |
IanBenzMaxim | 7:9cd16581b578 | 279 | |
IanBenzMaxim | 7:9cd16581b578 | 280 | template <typename T, typename U> |
IanBenzMaxim | 7:9cd16581b578 | 281 | bool operator<(const Optional<T> & opt, const U & value) { |
IanBenzMaxim | 7:9cd16581b578 | 282 | return opt.hasValue() ? opt.value() < value : true; |
IanBenzMaxim | 7:9cd16581b578 | 283 | } |
IanBenzMaxim | 7:9cd16581b578 | 284 | |
IanBenzMaxim | 7:9cd16581b578 | 285 | template <typename T, typename U> |
IanBenzMaxim | 7:9cd16581b578 | 286 | bool operator<(const T & value, const Optional<U> & opt) { |
IanBenzMaxim | 7:9cd16581b578 | 287 | return opt.hasValue() ? value < opt.value() : false; |
IanBenzMaxim | 7:9cd16581b578 | 288 | } |
IanBenzMaxim | 7:9cd16581b578 | 289 | |
IanBenzMaxim | 7:9cd16581b578 | 290 | template <typename T, typename U> |
IanBenzMaxim | 7:9cd16581b578 | 291 | bool operator<=(const Optional<T> & opt, const U & value) { |
IanBenzMaxim | 7:9cd16581b578 | 292 | return opt.hasValue() ? opt.value() <= value : true; |
IanBenzMaxim | 7:9cd16581b578 | 293 | } |
IanBenzMaxim | 7:9cd16581b578 | 294 | |
IanBenzMaxim | 7:9cd16581b578 | 295 | template <typename T, typename U> |
IanBenzMaxim | 7:9cd16581b578 | 296 | bool operator<=(const T & value, const Optional<U> & opt) { |
IanBenzMaxim | 7:9cd16581b578 | 297 | return opt.hasValue() ? value <= opt.value() : false; |
IanBenzMaxim | 7:9cd16581b578 | 298 | } |
IanBenzMaxim | 7:9cd16581b578 | 299 | |
IanBenzMaxim | 7:9cd16581b578 | 300 | template <typename T, typename U> |
IanBenzMaxim | 7:9cd16581b578 | 301 | bool operator>(const Optional<T> & opt, const U & value) { |
IanBenzMaxim | 7:9cd16581b578 | 302 | return opt.hasValue() ? opt.value() > value : false; |
IanBenzMaxim | 7:9cd16581b578 | 303 | } |
IanBenzMaxim | 7:9cd16581b578 | 304 | |
IanBenzMaxim | 7:9cd16581b578 | 305 | template <typename T, typename U> |
IanBenzMaxim | 7:9cd16581b578 | 306 | bool operator>(const T & value, const Optional<U> & opt) { |
IanBenzMaxim | 7:9cd16581b578 | 307 | return opt.hasValue() ? value > opt.value() : true; |
IanBenzMaxim | 7:9cd16581b578 | 308 | } |
IanBenzMaxim | 7:9cd16581b578 | 309 | |
IanBenzMaxim | 7:9cd16581b578 | 310 | template <typename T, typename U> |
IanBenzMaxim | 7:9cd16581b578 | 311 | bool operator>=(const Optional<T> & opt, const U & value) { |
IanBenzMaxim | 7:9cd16581b578 | 312 | return opt.hasValue() ? opt.value() >= value : false; |
IanBenzMaxim | 7:9cd16581b578 | 313 | } |
IanBenzMaxim | 7:9cd16581b578 | 314 | |
IanBenzMaxim | 7:9cd16581b578 | 315 | template <typename T, typename U> |
IanBenzMaxim | 7:9cd16581b578 | 316 | bool operator>=(const T & value, const Optional<U> & opt) { |
IanBenzMaxim | 7:9cd16581b578 | 317 | return opt.hasValue() ? value >= opt.value() : true; |
IanBenzMaxim | 7:9cd16581b578 | 318 | } |
IanBenzMaxim | 7:9cd16581b578 | 319 | |
IanBenzMaxim | 7:9cd16581b578 | 320 | } // namespace MaximInterfaceCore |
IanBenzMaxim | 7:9cd16581b578 | 321 | |
IanBenzMaxim | 7:9cd16581b578 | 322 | #endif |