16 #ifndef LLVM_ADT_OPTIONAL_H 17 #define LLVM_ADT_OPTIONAL_H 19 #include "llvm/None.h" 20 #include "llvm/AlignOf.h" 21 #include "llvm/Compiler.h" 35 Optional(NoneType) : hasVal(
false) {}
36 explicit Optional() : hasVal(
false) {}
37 Optional(
const T &y) : hasVal(
true) {
38 new (storage.buffer) T(y);
42 new (storage.buffer) T(*O);
46 new (storage.buffer) T(std::forward<T>(y));
50 new (storage.buffer) T(std::move(*O));
56 **
this = std::move(y);
58 new (storage.buffer) T(std::move(y));
67 *
this = std::move(*O);
74 template<
typename ...ArgTypes>
78 new (storage.buffer) T(std::forward<ArgTypes>(Args)...);
81 static inline Optional create(
const T* y) {
82 return y ?
Optional(*y) : Optional();
94 new (storage.buffer) T(y);
119 const T* getPointer()
const { assert(hasVal);
return reinterpret_cast<const T*
>(storage.buffer); }
120 T* getPointer() { assert(hasVal);
return reinterpret_cast<T*
>(storage.buffer); }
121 const T& getValue()
const LLVM_LVALUE_FUNCTION { assert(hasVal);
return *getPointer(); }
122 T& getValue() LLVM_LVALUE_FUNCTION { assert(hasVal);
return *getPointer(); }
124 explicit operator bool()
const {
return hasVal; }
125 bool hasValue()
const {
return hasVal; }
126 const T* operator->()
const {
return getPointer(); }
127 T* operator->() {
return getPointer(); }
128 const T& operator*()
const LLVM_LVALUE_FUNCTION { assert(hasVal);
return *getPointer(); }
129 T& operator*() LLVM_LVALUE_FUNCTION { assert(hasVal);
return *getPointer(); }
131 template <
typename U>
132 LLVM_CONSTEXPR T getValueOr(U &&value)
const LLVM_LVALUE_FUNCTION {
133 return hasValue() ? getValue() : std::forward<U>(value);
136 #if LLVM_HAS_RVALUE_REFERENCE_THIS 137 T&& getValue() && { assert(hasVal);
return std::move(*getPointer()); }
138 T&& operator*() && { assert(hasVal);
return std::move(*getPointer()); }
140 template <
typename U>
141 T getValueOr(U &&value) && {
142 return hasValue() ? std::move(getValue()) : std::forward<U>(value);
159 template<
typename T,
typename U>
164 return !X.hasValue();
187 template<
typename T,
typename U>
196 template<
typename T,
typename U>
197 void operator<(const Optional<T> &X,
const Optional<U> &Y);
205 template<
typename T,
typename U>
206 void operator<=(const Optional<T> &X,
const Optional<U> &Y);
214 template<
typename T,
typename U>
223 template<
typename T,
typename U>
Definition: Optional.h:29
isPodLike - This is a type trait that is used to determine whether a given type can be copied around ...
Definition: Optional.h:147
void emplace(ArgTypes &&...Args)
Create a new object by constructing it in place with the given arguments.
Definition: Optional.h:75