aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJordan Rose <jordan_rose@apple.com>2012-10-18 22:22:55 +0000
committerJordan Rose <jordan_rose@apple.com>2012-10-18 22:22:55 +0000
commit9d9a6128feb6e2251eb3bacdf2d1083a8b2f5b83 (patch)
tree3457d80764946451d45b25bf58ba1e212b77a3ba
parent82c5180ed1544a54731efcedee5a906683bbf888 (diff)
Add a T&& constructor to llvm::Optional.
This allows llvm::Optional to be used with movable-but-not-copyable types. While LLVM itself is still C++03, there's no reason why tools built on top of it can't use C++11 features. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@166241 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/llvm/ADT/Optional.h9
1 files changed, 9 insertions, 0 deletions
diff --git a/include/llvm/ADT/Optional.h b/include/llvm/ADT/Optional.h
index ee8b69f3d1..ffef8d91b3 100644
--- a/include/llvm/ADT/Optional.h
+++ b/include/llvm/ADT/Optional.h
@@ -16,8 +16,13 @@
#ifndef LLVM_ADT_OPTIONAL
#define LLVM_ADT_OPTIONAL
+#include "LLVM/Support/Compiler.h"
#include <cassert>
+#if LLVM_USE_RVALUE_REFERENCES
+#include <utility>
+#endif
+
namespace llvm {
template<typename T>
@@ -28,6 +33,10 @@ public:
explicit Optional() : x(), hasVal(false) {}
Optional(const T &y) : x(y), hasVal(true) {}
+#if LLVM_USE_RVALUE_REFERENCES
+ Optional(T &&y) : x(std::forward<T>(y)), hasVal(true) {}
+#endif
+
static inline Optional create(const T* y) {
return y ? Optional(*y) : Optional();
}