72 noexcept (std::is_nothrow_constructible_v<std::optional<Value>,
Head,
Tail...>)
73 : opt (std::forward<Head> (head), std::forward<Tail> (tail)...) {}
75 template <
typename Other>
80 template <
typename Other>
83 : opt (std::move (
other.opt)) {}
85 template <
typename Other, std::enable_if_t<! IsOptional<std::decay_t<Other>>::value,
int> = 0>
87 noexcept (std::is_nothrow_assignable_v<std::optional<Value>,
Other>)
89 opt = std::forward<Other> (
other);
93 template <
typename Other>
101 template <
typename Other>
105 opt = std::move (
other.opt);
109 template <
typename...
Other>
112 return opt.emplace (std::forward<Other> (
other)...);
115 void reset()
noexcept
121 noexcept (std::is_nothrow_swappable_v<std::optional<Value>>)
123 opt.swap (
other.opt);
126 decltype (
auto)
operator->() {
return opt.operator->(); }
127 decltype (
auto)
operator->()
const {
return opt.operator->(); }
128 decltype (
auto)
operator* () {
return opt.operator* (); }
129 decltype (
auto)
operator* ()
const {
return opt.operator* (); }
131 explicit operator bool()
const noexcept {
return opt.has_value(); }
132 bool hasValue()
const noexcept {
return opt.has_value(); }
134 template <
typename U>
135 decltype (
auto) orFallback (
U&& fallback)
const& {
return opt.value_or (std::forward<U> (fallback)); }
137 template <
typename U>
138 decltype (
auto) orFallback (
U&& fallback) & {
return opt.value_or (std::forward<U> (fallback)); }
141 template <typename T, typename U> friend bool operator op (const Optional<T>&, const Optional<U>&); \
142 template <typename T> friend bool operator op (const Optional<T>&, Nullopt); \
143 template <typename T> friend bool operator op (Nullopt, const Optional<T>&); \
144 template <typename T, typename U> friend bool operator op (const Optional<T>&, const U&); \
145 template <typename T, typename U> friend bool operator op (const T&, const Optional<U>&);
152 template <
typename Other>