38 using safe_bool = void (
optional::*)()
const;
47 optional(T
const &arg) : has_value_(true), value_(arg) {}
49 template<
class U>
optional(
optional<U> const &other) : has_value_(other.has_value()), value_(other.value()) {}
58 value_ = other.
value();
64 if (has_value() && rhs.has_value()) {
66 }
else if (!has_value() && rhs.has_value()) {
69 }
else if (has_value() && !rhs.has_value()) {
70 rhs.initialize(**
this);
85 operator safe_bool()
const {
return has_value() ? &optional::this_type_does_not_support_comparisons :
nullptr; }
97 void reset() { has_value_ =
false; }
100 void this_type_does_not_support_comparisons()
const {}
102 template<
typename V>
void initialize(V
const &value) {
107 bool has_value_{
false};
114 return bool(x) != bool(y) ? false : !bool(x) ? true : *x == *
y;
121 template<
typename T,
typename U>
inline bool operator<(optional<T>
const &
x,
optional<U> const &
y) {
122 return (!
y) ? false : (!
x) ?
true : *x < *
y;
127 template<
typename T,
typename U>
inline bool operator<=(optional<T>
const &
x,
optional<U> const &
y) {
return !(
y <
x); }
141 template<
typename T>
inline bool operator<(optional<T>
const & ,
nullopt_t ) {
return false; }
145 template<
typename T>
inline bool operator<=(optional<T>
const &
x,
nullopt_t ) {
return (!x); }
160 return bool(x) ? *x == v :
false;
164 return bool(x) ? v == *
x :
false;
168 return bool(x) ? *x != v :
true;
172 return bool(x) ? v != *
x :
true;
175 template<
typename T,
typename U>
inline bool operator<(optional<T>
const &
x, U
const &v) {
176 return bool(x) ? *x < v :
true;
179 template<
typename T,
typename U>
inline bool operator<(U const &v, optional<T>
const &
x) {
180 return bool(x) ? v < *
x :
false;
183 template<
typename T,
typename U>
inline bool operator<=(optional<T>
const &
x, U
const &v) {
184 return bool(x) ? *x <= v :
true;
187 template<
typename T,
typename U>
inline bool operator<=(U const &v, optional<T>
const &
x) {
188 return bool(x) ? v <= *
x :
false;
192 return bool(x) ? *x > v :
false;
196 return bool(x) ? v > *
x :
true;
200 return bool(x) ? *x >= v :
false;
204 return bool(x) ? v >= *
x :
true;
optional< T > make_optional(T const &v)
value_type const & value() const
value_type const & operator*() const
write_transform_func_t value_type
const nullopt_t nullopt((nullopt_t::init()))
void swap(optional &rhs) noexcept
value_type const * operator->() const
bool operator>(optional< T > const &x, optional< U > const &y)
bool operator>=(optional< T > const &x, optional< U > const &y)
optional & operator=(nullopt_t)
bool operator<=(optional< T > const &x, optional< U > const &y)
bool operator!=(optional< T > const &x, optional< U > const &y)
bool operator<(optional< T > const &x, optional< U > const &y)
bool operator==(optional< T > const &x, optional< U > const &y)
value_type * operator->()
Implementation of SPI Controller mode.
optional(optional< U > const &other)
optional & operator=(optional< U > const &other)
value_type value_or(U const &v) const
void swap(optional< T > &x, optional< T > &y) noexcept