15 #ifndef LLVM_ADT_OPTIONAL_H 16 #define LLVM_ADT_OPTIONAL_H 30 namespace optional_detail {
35 template <typename T, bool = is_trivially_copyable<T>::value>
54 if (other.hasValue()) {
55 emplace(std::move(other.value));
59 template <
class...
Args>
61 : value(
std::forward<
Args>(args)...), hasVal(
true) {}
80 #if LLVM_HAS_RVALUE_REFERENCE_THIS 81 T &&getValue() && noexcept {
83 return std::move(value);
89 ::new ((
void *)std::addressof(value))
T(std::forward<Args>(args)...);
97 ::new ((
void *)std::addressof(value))
T(y);
104 value = std::move(y);
106 ::new ((
void *)std::addressof(value))
T(std::move(y));
117 ::new ((
void *)std::addressof(value))
T(other.
value);
127 if (other.hasValue()) {
129 value = std::move(other.value);
131 ::new ((
void *)std::addressof(value))
T(std::move(other.value));
159 template <
class...
Args>
161 : value(
std::forward<
Args>(args)...), hasVal(
true) {}
180 #if LLVM_HAS_RVALUE_REFERENCE_THIS 181 T &&getValue() && noexcept {
183 return std::move(value);
189 ::new ((
void *)std::addressof(value))
T(std::forward<Args>(args)...);
197 ::new ((
void *)std::addressof(value))
T(y);
204 value = std::move(y);
206 ::new ((
void *)std::addressof(value))
T(std::move(y));
215 template <
typename T>
class Optional {
224 Optional(
const T &y) : Storage(optional_detail::in_place_t{}, y) {}
227 Optional(
T &&y) : Storage(optional_detail::in_place_t{}, std::move(y)) {}
231 Storage = std::move(y);
237 template <
typename... ArgTypes>
void emplace(ArgTypes &&...
Args) {
258 explicit operator bool()
const {
return hasValue(); }
265 template <
typename U>
267 return hasValue() ? getValue() : std::forward<U>(value);
271 template <
class Function>
274 if (*
this)
return F(getValue());
278 #if LLVM_HAS_RVALUE_REFERENCE_THIS 279 T &&getValue() && {
return std::move(Storage.
getValue()); }
282 template <
typename U>
283 T getValueOr(U &&value) && {
284 return hasValue() ? std::move(getValue()) : std::forward<U>(value);
288 template <
class Function>
290 ->
Optional<decltype(
F(std::move(*this).getValue()))> {
291 if (*
this)
return F(std::move(*this).getValue());
297 template <
typename T,
typename U>
304 template <
typename T,
typename U>
309 template <
typename T,
typename U>
313 return X.hasValue() < Y.hasValue();
316 template <
typename T,
typename U>
321 template <
typename T,
typename U>
326 template <
typename T,
typename U>
351 template <
typename T>
bool operator<(const Optional<T> &
X,
NoneType) {
355 template <
typename T>
bool operator<(NoneType, const Optional<T> &
X) {
359 template <
typename T>
bool operator<=(const Optional<T> &
X,
NoneType) {
363 template <
typename T>
bool operator<=(NoneType, const Optional<T> &
X) {
399 template <
typename T>
bool operator<(const Optional<T> &
X,
const T &
Y) {
403 template <
typename T>
bool operator<(const T &X, const Optional<T> &
Y) {
407 template <
typename T>
bool operator<=(const Optional<T> &
X,
const T &
Y) {
411 template <
typename T>
bool operator<=(const T &X, const Optional<T> &
Y) {
433 template <
typename T,
typename = decltype(std::declval<raw_ostream &>()
434 << std::declval<const T &>())>
435 raw_ostream &operator<<(raw_ostream &OS, const Optional<T> &O) {
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
const T & operator*() const LLVM_LVALUE_FUNCTION
This class represents lattice values for constants.
NoneType
A simple null object to allow implicit construction of Optional<T> and similar types without having t...
bool operator>(int64_t V1, const APSInt &V2)
constexpr T getValueOr(U &&value) const LLVM_LVALUE_FUNCTION
void emplace(ArgTypes &&... Args)
Create a new object by constructing it in place with the given arguments.
OptionalStorage(OptionalStorage const &other)
OptionalStorage(OptionalStorage &&other)
block Block Frequency true
OptionalStorage(in_place_t, Args &&... args)
static GCMetadataPrinterRegistry::Add< OcamlGCMetadataPrinter > Y("ocaml", "ocaml 3.10-compatible collector")
T & getValue() LLVM_LVALUE_FUNCTION
bool operator>=(int64_t V1, const APSInt &V2)
OptionalStorage & operator=(T const &y)
#define LLVM_LVALUE_FUNCTION
Expands to '&' if ref-qualifiers for *this are supported.
auto map(const Function &F) const -> Optional< decltype(F(getValue()))>
Apply a function to the value if present; otherwise return None.
Optional & operator=(const T &y)
APInt operator*(APInt a, uint64_t RHS)
OptionalStorage & operator=(T &&y)
const T & getValue() const LLVM_LVALUE_FUNCTION
OptionalStorage & operator=(T const &y)
const T * operator->() const
static Optional create(const T *y)
bool hasValue() const noexcept
OptionalStorage & operator=(T &&y)
OptionalStorage() noexcept
T & operator*() LLVM_LVALUE_FUNCTION
const T * getPointer() const
constexpr Optional(NoneType)
constexpr bool empty(const T &RangeOrContainer)
Test whether RangeOrContainer is empty. Similar to C++17 std::empty.
void emplace(Args &&... args)
T const & getValue() const LLVM_LVALUE_FUNCTION noexcept
OptionalStorage(in_place_t, Args &&... args)
T & getValue() LLVM_LVALUE_FUNCTION noexcept
T const & getValue() const LLVM_LVALUE_FUNCTION noexcept
bool operator!=(uint64_t V1, const APInt &V2)
OptionalStorage & operator=(OptionalStorage &&other)
bool hasValue() const noexcept
Optional & operator=(T &&y)
OptionalStorage & operator=(OptionalStorage const &other)
raw_ostream & operator<<(raw_ostream &OS, const APInt &I)
OptionalStorage() noexcept
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
T & getValue() LLVM_LVALUE_FUNCTION noexcept
This class implements an extremely fast bulk output stream that can only output to a stream...
bool operator==(uint64_t V1, const APInt &V2)
void emplace(Args &&... args)
constexpr char Args[]
Key for Kernel::Metadata::mArgs.