60 #include <type_traits> 70 template <
class Value>
74 template <
class Value>
92 :
std::runtime_error(
"Empty Optional cannot be unwrapped") {}
95 template <
class Value>
102 "Optional may not be used with reference types");
105 "Optional may not be used with abstract types");
111 if (src.hasValue()) {
112 construct(src.value());
118 if (src.hasValue()) {
139 template <
typename Null = std::
nullptr_t>
146 template <
typename...
Args>
149 :
Optional{PrivateConstructor{}, std::forward<Args>(args)...} {}
151 template <
typename U,
typename...
Args>
154 std::initializer_list<U> il,
156 is_nothrow_constructible<
158 std::initializer_list<U>,
160 :
Optional{PrivateConstructor{}, il, std::forward<Args>(args)...} {}
165 p.promise_->value_ =
this;
174 if (src.hasValue()) {
201 storage_.value = newValue;
214 assign(std::forward<Arg>(arg));
230 template <
class...
Args>
233 construct(std::forward<Args>(args)...);
237 template <
class U,
class...
Args>
238 typename std::enable_if<
239 std::is_constructible<Value, std::initializer_list<U>&,
Args&&...>
::value,
243 construct(ilist, std::forward<Args>(args)...);
256 if (hasValue() && that.hasValue()) {
259 }
else if (hasValue()) {
262 }
else if (that.hasValue()) {
270 return storage_.value;
275 return storage_.value;
289 return storage_.hasValue ? &storage_.value :
nullptr;
292 return storage_.hasValue ? &storage_.value :
nullptr;
297 return storage_.hasValue;
331 if (storage_.hasValue) {
332 return storage_.value;
335 return std::forward<U>(dflt);
340 if (storage_.hasValue) {
344 return std::forward<U>(dflt);
350 template <
class T,
class...
Args>
352 template <
class T,
class U,
class... As>
366 template <
typename...
Args>
369 construct(std::forward<Args>(args)...);
373 if (!storage_.hasValue) {
374 throw_exception<OptionalEmptyException>();
378 template <
class...
Args>
380 const void*
ptr = &storage_.value;
382 new (
const_cast<void*
>(
ptr))
Value(std::forward<Args>(args)...);
383 storage_.hasValue =
true;
426 using Storage =
typename std::conditional<
451 using PrivateConstructor =
453 return {PrivateConstructor{}, std::forward<T>(
v)};
456 template <
class T,
class...
Args>
459 return {PrivateConstructor{}, std::forward<Args>(args)...};
462 template <
class T,
class U,
class...
Args>
464 std::initializer_list<U> il,
467 return {PrivateConstructor{}, il, std::forward<Args>(args)...};
473 template <
class U,
class V>
478 template <
class U,
class V>
483 template <
class U,
class V>
488 template <
class U,
class V>
493 template <
class U,
class V>
506 template <
class U,
class V>
511 template <
class U,
class V>
524 template <
class U,
class V>
529 template <
class U,
class V>
534 template <
class U,
class V>
541 bool operator<(const Optional<V>&,
const V& other) =
delete;
543 bool operator<=(const Optional<V>&,
const V& other) =
delete;
549 bool operator<(const V& other, const Optional<V>&) =
delete;
551 bool operator<=(const V& other, const Optional<V>&) =
delete;
564 return !a.hasValue();
571 constexpr
bool operator<(None, const Optional<V>&
a)
noexcept {
583 constexpr
bool operator<=(None, const Optional<V>&)
noexcept {
588 return !a.hasValue();
596 return !a.hasValue();
618 #if FOLLY_HAS_COROUTINES 619 #include <experimental/coroutine> 623 template <
typename Value>
624 struct OptionalPromise;
626 template <
typename Value>
627 struct OptionalPromiseReturn {
628 Optional<Value> storage_;
630 OptionalPromiseReturn(OptionalPromise<Value>& promise)
noexcept 632 promise.value_ = &storage_;
634 OptionalPromiseReturn(OptionalPromiseReturn&& that)
noexcept 635 : OptionalPromiseReturn{*that.promise_} {}
636 ~OptionalPromiseReturn() {}
637 operator Optional<Value>() & {
642 template <
typename Value>
643 struct OptionalPromise {
644 Optional<Value>* value_ =
nullptr;
645 OptionalPromise() =
default;
646 OptionalPromise(OptionalPromise
const&) =
delete;
651 OptionalPromiseReturn<Value> get_return_object()
noexcept {
654 std::experimental::suspend_never initial_suspend()
const noexcept {
657 std::experimental::suspend_never final_suspend()
const {
660 template <
typename U>
661 void return_value(U&& u) {
662 *value_ =
static_cast<U&&
>(u);
664 void unhandled_exception() {
671 template <
typename Value>
672 struct OptionalAwaitable {
675 return o_.hasValue();
677 Value await_resume() {
682 template <
typename U>
684 std::experimental::coroutine_handle<OptionalPromise<U>>
h)
const {
691 template <
typename Value>
692 detail::OptionalAwaitable<Value>
693 operator co_await(Optional<Value> o) {
700 namespace experimental {
701 template <
typename Value,
typename...
Args>
702 struct coroutine_traits<folly::Optional<Value>,
Args...> {
703 using promise_type = folly::detail::OptionalPromise<Value>;
707 #endif // FOLLY_HAS_COROUTINES FOLLY_CPP14_CONSTEXPR Value && value()&&
bool operator>(const Expected< Value, Error > &lhs, const Expected< Value, Error > &rhs)
#define FOLLY_POP_WARNING
Optional(Optional &&src) noexcept(std::is_nothrow_move_constructible< Value >::value)
FOLLY_CPP14_CONSTEXPR Optional(Value &&newValue) noexcept(std::is_nothrow_move_constructible< Value >::value)
#define FOLLY_PUSH_WARNING
FOLLY_CPP14_CONSTEXPR Optional(in_place_t, std::initializer_list< U > il, Args &&...args) noexcept(std::is_nothrow_constructible< Value, std::initializer_list< U >, Args... >::value)
FOLLY_CPP14_CONSTEXPR Value && operator*()&&
void construct(Args &&...args)
void assign(const Optional &src)
void assign(const None &)
#define FOLLY_CPP14_CONSTEXPR
constexpr detail::Map< Move > move
Optional & operator=(Optional &&other) noexcept(std::is_nothrow_move_assignable< Value >::value)
FOLLY_POP_WARNING void clear()
FOLLY_CPP14_CONSTEXPR const Value && operator*() const &&
FOLLY_CPP14_CONSTEXPR bool has_value() const noexcept
void assign(Value &&newValue)
void swap(Optional &that) noexcept(IsNothrowSwappable< Value >::value)
internal::ArgsMatcher< InnerMatcher > Args(const InnerMatcher &matcher)
—— Concurrent Priority Queue Implementation ——
requires E e noexcept(noexcept(s.error(std::move(e))))
in_place_tag(&)(in_place_tag) in_place_t
void assign(const Value &newValue)
FOLLY_CPP14_CONSTEXPR Value * operator->()
StorageTriviallyDestructible()
constexpr Optional< _t< std::decay< T > > > make_optional(T &&v)
~StorageNonTriviallyDestructible()
bool operator!=(const Unexpected< Error > &lhs, const Unexpected< Error > &rhs)
FOLLY_PUSH_WARNING FOLLY_MSVC_DISABLE_WARNING(4388) FOLLY_MSVC_DISABLE_WARNING(4804) template< typename RHS
FOLLY_CPP14_CONSTEXPR Optional() noexcept
const Value * get_pointer() const &
#define FOLLY_NAMESPACE_STD_BEGIN
FOLLY_CPP14_CONSTEXPR Optional(const None &) noexcept
FOLLY_CPP14_CONSTEXPR const Value & operator*() const &
size_t operator()(folly::Optional< T > const &obj) const
FOLLY_PUSH_WARNING FOLLY_MSVC_DISABLE_WARNING(4587) FOLLY_MSVC_DISABLE_WARNING(4588) StorageNonTriviallyDestructible()
bool Value(const T &value, M matcher)
typename std::conditional< std::is_trivially_destructible< Value >::value, StorageTriviallyDestructible, StorageNonTriviallyDestructible >::type Storage
FOLLY_CPP14_CONSTEXPR bool hasValue() const noexcept
void require_value() const
FOLLY_CPP14_CONSTEXPR Optional(PrivateConstructor, Args &&...args) noexcept(std::is_constructible< Value, Args &&... >::value)
static const char *const value
Value & emplace(Args &&...args)
Optional & operator=(None) noexcept
Optional(const Optional &src) noexcept(std::is_nothrow_copy_constructible< Value >::value)
FOLLY_CPP14_CONSTEXPR Value value_or(U &&dflt)&&
FOLLY_CPP14_CONSTEXPR Value value_or(U &&dflt) const &
void assign(Optional &&src)
Optional & operator=(Arg &&arg)
bool operator>=(const Expected< Value, Error > &lhs, const Expected< Value, Error > &rhs)
FOLLY_CPP14_CONSTEXPR Value & operator*()&
const Value * get_pointer(const Expected< Value, Error > &ex) noexcept
void swap(exception_wrapper &a, exception_wrapper &b) noexcept
std::enable_if< std::is_constructible< Value, std::initializer_list< U > &, Args &&... >::value, Value & >::type emplace(std::initializer_list< U > ilist, Args &&...args)
FOLLY_CPP14_CONSTEXPR const Value && value() const &&
bool operator==(const Unexpected< Error > &lhs, const Unexpected< Error > &rhs)
Optional(const detail::OptionalPromiseReturn< Value > &p)
FOLLY_CPP14_CONSTEXPR Optional(const Value &newValue) noexcept(std::is_nothrow_copy_constructible< Value >::value)
uint64_t value(const typename LockFreeRingBuffer< T, Atom >::Cursor &rbcursor)
FOLLY_CPP14_CONSTEXPR Optional(typename std::enable_if< !std::is_pointer< Value >::value &&std::is_same< Null, std::nullptr_t >::value, Null >::type) noexcept
FOLLY_CPP14_CONSTEXPR Value & value()&
FOLLY_CPP14_CONSTEXPR const Value & value() const &
void swap(Optional< T > &a, Optional< T > &b) noexcept(noexcept(a.swap(b)))
FOLLY_CPP14_CONSTEXPR const Value * operator->() const
std::enable_if< IsLessThanComparable< Value >::value, bool >::type operator<(const Expected< Value, Error > &lhs, const Expected< Value, Error > &rhs)
#define FOLLY_NAMESPACE_STD_END
FOLLY_CPP14_CONSTEXPR Optional(in_place_t, Args &&...args) noexcept(std::is_nothrow_constructible< Value, Args... >::value)
Optional & operator=(const Optional &other) noexcept(std::is_nothrow_copy_assignable< Value >::value)