1 //===--- MSVCErrorWorkarounds.h - Enable future<Error> in MSVC --*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // MSVC's promise/future implementation requires types to be default
11 // constructible, so this header provides analogues of Error an Expected
12 // that are default constructed in a safely destructible state.
14 // FIXME: Kill off this header and migrate all users to Error/Expected once we
15 // move to MSVC versions that support non-default-constructible types.
17 //===----------------------------------------------------------------------===//
19 #ifndef LLVM_SUPPORT_MSVCERRORWORKAROUNDS_H
20 #define LLVM_SUPPORT_MSVCERRORWORKAROUNDS_H
22 #include "llvm/Support/Error.h"
26 // A default-constructible llvm::Error that is suitable for use with MSVC's
27 // std::future implementation which requires default constructible types.
28 class MSVCPError : public Error {
30 MSVCPError() { (void)!!*this; }
32 MSVCPError(MSVCPError &&Other) : Error(std::move(Other)) {}
34 MSVCPError &operator=(MSVCPError Other) {
35 Error::operator=(std::move(Other));
39 MSVCPError(Error Err) : Error(std::move(Err)) {}
42 // A default-constructible llvm::Expected that is suitable for use with MSVC's
43 // std::future implementation, which requires default constructible types.
44 template <typename T> class MSVCPExpected : public Expected<T> {
47 : Expected<T>(make_error<StringError>("", inconvertibleErrorCode())) {
48 consumeError(this->takeError());
51 MSVCPExpected(MSVCPExpected &&Other) : Expected<T>(std::move(Other)) {}
53 MSVCPExpected &operator=(MSVCPExpected &&Other) {
54 Expected<T>::operator=(std::move(Other));
58 MSVCPExpected(Error Err) : Expected<T>(std::move(Err)) {}
60 template <typename OtherT>
63 typename std::enable_if<std::is_convertible<OtherT, T>::value>::type * =
65 : Expected<T>(std::move(Val)) {}
67 template <class OtherT>
69 Expected<OtherT> &&Other,
70 typename std::enable_if<std::is_convertible<OtherT, T>::value>::type * =
72 : Expected<T>(std::move(Other)) {}
74 template <class OtherT>
75 explicit MSVCPExpected(
76 Expected<OtherT> &&Other,
77 typename std::enable_if<!std::is_convertible<OtherT, T>::value>::type * =
79 : Expected<T>(std::move(Other)) {}
82 } // end namespace llvm
84 #endif // LLVM_SUPPORT_MSVCERRORWORKAROUNDS_H