13 #ifndef __STOUT_OPTION_HPP__
14 #define __STOUT_OPTION_HPP__
20 #include <type_traits>
22 #include <boost/functional/hash.hpp>
43 Option(
const T& _t) : state(SOME),
t(_t) {}
45 Option(T&& _t) : state(SOME),
t(std::move(_t)) {}
49 typename =
typename std::enable_if<
50 std::is_constructible<T, const U&>::value>
::type>
69 noexcept(std::is_nothrow_move_constructible<T>::value)
70 : state(std::move(that.state))
73 new (&
t) T(std::move(that.t));
100 noexcept(std::is_nothrow_move_constructible<T>::value)
106 state = std::move(that.state);
108 new (&
t) T(std::move(that.t));
115 bool isSome()
const {
return state == SOME; }
116 bool isNone()
const {
return state == NONE; }
118 const T&
get()
const & { assert(
isSome());
return t; }
120 T&&
get() && { assert(
isSome());
return std::move(
t); }
121 const T&&
get()
const && { assert(
isSome());
return std::move(
t); }
137 return !(*
this == that);
147 return !(*
this == that);
169 template <
typename T>
174 }
else if (left.
isSome()) {
176 }
else if (right.
isSome()) {
184 template <
typename T>
191 template <
typename T>
198 template <
typename T>
203 }
else if (left.
isSome()) {
205 }
else if (right.
isSome()) {
213 template <
typename T>
220 template <
typename T>
228 template <
typename T>
239 boost::hash_combine(seed, hash<T>()(option.
get()));
247 #endif // __STOUT_OPTION_HPP__
Definition: option.hpp:28
size_t result_type
Definition: option.hpp:231
std::remove_const< T >::type t
Definition: option.hpp:164
const T * operator->() const
Definition: option.hpp:123
bool operator!=(const T &that) const
Definition: option.hpp:145
bool operator==(const T &that) const
Definition: option.hpp:140
bool operator!=(const Option< T > &that) const
Definition: option.hpp:135
noexcept(std::is_nothrow_move_constructible< T >::value)
Definition: option.hpp:69
bool isSome() const
Definition: option.hpp:115
static Option< T > some(const T &t)
Definition: option.hpp:36
Option(const U &u)
Definition: option.hpp:51
~Option()
Definition: option.hpp:77
Option< T > argument_type
Definition: option.hpp:233
Option< T > max(const Option< T > &left, const Option< T > &right)
Definition: option.hpp:199
Option< T > & operator=(const Option< T > &that)
Definition: option.hpp:84
Option(const _Some< U > &some)
Definition: option.hpp:56
static Option< T > none()
Definition: option.hpp:31
Option< T > min(const Option< T > &left, const Option< T > &right)
Definition: option.hpp:170
Option()
Definition: option.hpp:41
const T & get() const &
Definition: option.hpp:118
result_type operator()(const argument_type &option) const
Definition: option.hpp:235
Option(const Option< T > &that)
Definition: option.hpp:61
Option(T &&_t)
Definition: option.hpp:45
Try< uint32_t > type(const std::string &path)
bool isNone() const
Definition: option.hpp:116
T * operator->()
Definition: option.hpp:124
Option< T > & operator=(Option< T > &&that) noexcept(std::is_nothrow_move_constructible< T >::value)
Definition: option.hpp:99
Option(_Some< U > &&some)
Definition: option.hpp:59
T getOrElse(const T &_t) const
Definition: option.hpp:127
bool operator==(const Option< T > &that) const
Definition: option.hpp:129
Option(const None &)
Definition: option.hpp:53
Option(const T &_t)
Definition: option.hpp:43