13 #ifndef __STOUT_OPTION_HPP__ 14 #define __STOUT_OPTION_HPP__ 20 #include <type_traits> 23 #include <boost/functional/hash.hpp> 44 Option(
const T& _t) : state(SOME),
t(_t) {}
50 typename =
typename std::enable_if<
51 std::is_constructible<T, const U&>::value>
::type>
70 noexcept(
std::is_nothrow_move_constructible<T>::value)
71 : state(
std::move(that.state))
74 new (&
t) T(std::move(that.t));
101 noexcept(
std::is_nothrow_move_constructible<T>::value)
107 state = std::move(that.state);
109 new (&
t) T(std::move(that.t));
116 bool isSome()
const {
return state == SOME; }
117 bool isNone()
const {
return state == NONE; }
119 const T&
get()
const & { assert(
isSome());
return t; }
121 T&&
get() && { assert(
isSome());
return std::move(
t); }
122 const T&&
get()
const && { assert(
isSome());
return std::move(
t); }
129 const T&&
operator*() const&& {
return std::move(*this).get(); }
132 template <
typename U>
135 return isNone() ?
static_cast<T
>(std::forward<U>(u)) :
t;
138 template <
typename U>
141 return isNone() ?
static_cast<T
>(std::forward<U>(u)) : std::move(
t);
152 return !(*
this == that);
162 return !(*
this == that);
184 template <
typename T>
189 }
else if (left.
isSome()) {
191 }
else if (right.
isSome()) {
199 template <
typename T>
206 template <
typename T>
213 template <
typename T>
218 }
else if (left.
isSome()) {
220 }
else if (right.
isSome()) {
228 template <
typename T>
235 template <
typename T>
243 template <
typename T>
254 boost::hash_combine(seed, hash<T>()(option.
get()));
262 #endif // __STOUT_OPTION_HPP__ Definition: option.hpp:29
T getOrElse(U &&u) const &
Definition: option.hpp:133
const T && operator*() const &&
Definition: option.hpp:129
Option(Option< T > &&that) noexcept(std::is_nothrow_move_constructible< T >::value)
Definition: option.hpp:69
T getOrElse(U &&u)&&
Definition: option.hpp:139
size_t result_type
Definition: option.hpp:246
std::remove_const< T >::type t
Definition: option.hpp:179
const T * operator->() const
Definition: option.hpp:124
Definition: type_utils.hpp:619
bool operator!=(const T &that) const
Definition: option.hpp:160
bool operator==(const T &that) const
Definition: option.hpp:155
bool operator!=(const Option< T > &that) const
Definition: option.hpp:150
bool isSome() const
Definition: option.hpp:116
static Option< T > some(const T &t)
Definition: option.hpp:37
Option(const U &u)
Definition: option.hpp:52
~Option()
Definition: option.hpp:78
Option< T > argument_type
Definition: option.hpp:248
Option< T > max(const Option< T > &left, const Option< T > &right)
Definition: option.hpp:214
Option< T > & operator=(const Option< T > &that)
Definition: option.hpp:85
Option(const _Some< U > &some)
Definition: option.hpp:57
static Option< T > none()
Definition: option.hpp:32
Option< T > min(const Option< T > &left, const Option< T > &right)
Definition: option.hpp:185
Option()
Definition: option.hpp:42
const T & get() const &
Definition: option.hpp:119
result_type operator()(const argument_type &option) const
Definition: option.hpp:250
T && operator*()&&
Definition: option.hpp:130
Option(const Option< T > &that)
Definition: option.hpp:62
Option(T &&_t)
Definition: option.hpp:46
Try< uint32_t > type(const std::string &path)
bool isNone() const
Definition: option.hpp:117
T * operator->()
Definition: option.hpp:125
T & operator*()&
Definition: option.hpp:128
Option< T > & operator=(Option< T > &&that) noexcept(std::is_nothrow_move_constructible< T >::value)
Definition: option.hpp:100
Option(_Some< U > &&some)
Definition: option.hpp:60
bool operator==(const Option< T > &that) const
Definition: option.hpp:144
const T & operator*() const &
Definition: option.hpp:127
Option(const None &)
Definition: option.hpp:54
Option(const T &_t)
Definition: option.hpp:44