16 #ifndef LLVM_SUPPORT_ERROR_OR_H
17 #define LLVM_SUPPORT_ERROR_OR_H
25 #if LLVM_HAS_CXX11_TYPETRAITS
26 #include <type_traits>
30 #if LLVM_HAS_CXX11_TYPETRAITS && LLVM_HAS_RVALUE_REFERENCES
31 template<
class T,
class V>
32 typename std::enable_if< std::is_constructible<T, V>::value
33 ,
typename std::remove_reference<V>::type>::type &&
35 return std::move(Val);
38 template<
class T,
class V>
39 typename std::enable_if< !std::is_constructible<T, V>::value
40 ,
typename std::remove_reference<V>::type>::type &
45 template<
class T,
class V>
59 operator T &()
const {
return *Storage; }
60 T &
get()
const {
return *Storage; }
95 template <
class OtherT>
friend class ErrorOr;
124 new (
get())
storage_type(moveIfMoveConstructible<storage_type>(Val));
128 copyConstruct(Other);
131 template <
class OtherT>
133 copyConstruct(Other);
141 template <
class OtherT>
147 #if LLVM_HAS_RVALUE_REFERENCES
149 moveConstruct(std::move(Other));
152 template <
class OtherT>
153 ErrorOr(ErrorOr<OtherT> &&Other) {
154 moveConstruct(std::move(Other));
158 moveAssign(std::move(Other));
162 template <
class OtherT>
164 moveAssign(std::move(Other));
187 return toPointer(
get());
195 template <
class OtherT>
197 if (!Other.HasError) {
204 new (getError()) error_code(Other);
209 static bool compareThisIfSameType(
const T1 &a,
const T1 &b) {
213 template <
class T1,
class T2>
214 static bool compareThisIfSameType(
const T1 &a,
const T2 &b) {
218 template <
class OtherT>
219 void copyAssign(
const ErrorOr<OtherT> &Other) {
220 if (compareThisIfSameType(*
this, Other))
227 #if LLVM_HAS_RVALUE_REFERENCES
228 template <
class OtherT>
229 void moveConstruct(ErrorOr<OtherT> &&Other) {
230 if (!Other.HasError) {
237 new (getError()) error_code(Other);
241 template <
class OtherT>
242 void moveAssign(ErrorOr<OtherT> &&Other) {
243 if (compareThisIfSameType(*
this, Other))
247 new (
this)
ErrorOr(std::move(Other));
251 pointer toPointer(pointer Val) {
255 pointer toPointer(
wrap *Val) {
260 assert(!HasError &&
"Cannot get value when an error exists!");
265 assert(!HasError &&
"Cannot get value when an error exists!");
269 error_code *getError() {
270 assert(HasError &&
"Cannot get error when a value exists!");
271 return reinterpret_cast<error_code*
>(
ErrorStorage.buffer);
274 const error_code *getError()
const {
275 return const_cast<ErrorOr<T> *
>(
this)->getError();
286 template<
class T,
class E>
287 typename enable_if_c<is_error_code_enum<E>::value ||
288 is_error_condition_enum<E>::value,
bool>::type
Represents either an error or a value T.
ErrorOr & operator=(const ErrorOr &Other)
ErrorOr(llvm::error_code EC)
ErrorOr(E ErrorCode, typename enable_if_c< is_error_code_enum< E >::value||is_error_condition_enum< E >::value, void * >::type=0)
void(* unspecified_bool_type)()
AlignedCharArrayUnion< error_code > ErrorStorage
conditional< isRef, wrap, T >::type storage_type
ErrorOr(const ErrorOr< OtherT > &Other)
V & moveIfMoveConstructible(V &Val)
ErrorOr(const ErrorOr &Other)
AlignedCharArrayUnion< storage_type > TStorage
static void unspecified_bool_true()
LLVMContextRef * wrap(const LLVMContext **Tys)
static error_code success()
Stores a reference that can be changed.
Metafunction that determines wheather the given type is a reference.
bool operator==(uint64_t V1, const APInt &V2)
error_code make_error_code(errc _e)