[PATCH] D135940: [SaveAndRestore] Upgrade this to support non-copyable types.

Chris Lattner via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 14 08:14:26 PDT 2022


This revision was automatically updated to reflect the committed changes.
Closed by commit rG1dee803afab1: [SaveAndRestore] Upgrade this to support non-copyable types. (authored by lattner).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D135940/new/

https://reviews.llvm.org/D135940

Files:
  llvm/include/llvm/Support/SaveAndRestore.h


Index: llvm/include/llvm/Support/SaveAndRestore.h
===================================================================
--- llvm/include/llvm/Support/SaveAndRestore.h
+++ llvm/include/llvm/Support/SaveAndRestore.h
@@ -20,11 +20,12 @@
 /// A utility class that uses RAII to save and restore the value of a variable.
 template <typename T> struct SaveAndRestore {
   SaveAndRestore(T &X) : X(X), OldValue(X) {}
-  SaveAndRestore(T &X, const T &NewValue) : X(X), OldValue(X) {
-    X = NewValue;
+  SaveAndRestore(T &X, const T &NewValue) : X(X), OldValue(X) { X = NewValue; }
+  SaveAndRestore(T &X, T &&NewValue) : X(X), OldValue(std::move(X)) {
+    X = std::move(NewValue);
   }
-  ~SaveAndRestore() { X = OldValue; }
-  T get() { return OldValue; }
+  ~SaveAndRestore() { X = std::move(OldValue); }
+  const T &get() { return OldValue; }
 
 private:
   T &X;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D135940.467781.patch
Type: text/x-patch
Size: 859 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221014/2be3d542/attachment.bin>


More information about the llvm-commits mailing list