llvm.org GIT mirror llvm / 925c3f0
Move include/llvm/ADT/SaveAndRestore.h -> include/llvm/Support/SaveAndRestore.h git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@151828 91177308-0d34-0410-b5e6-96231b3b80d8 Argyrios Kyrtzidis 8 years ago
2 changed file(s) with 47 addition(s) and 47 deletion(s). Raw diff Collapse all Expand all
+0
-47
include/llvm/ADT/SaveAndRestore.h less more
None //===-- SaveAndRestore.h - Utility -------------------------------*- C++ -*-=//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file provides utility classes that uses RAII to save and restore
10 // values.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_ADT_SAVERESTORE
15 #define LLVM_ADT_SAVERESTORE
16
17 namespace llvm {
18
19 // SaveAndRestore - A utility class that uses RAII to save and restore
20 // the value of a variable.
21 template
22 struct SaveAndRestore {
23 SaveAndRestore(T& x) : X(x), old_value(x) {}
24 SaveAndRestore(T& x, const T &new_value) : X(x), old_value(x) {
25 X = new_value;
26 }
27 ~SaveAndRestore() { X = old_value; }
28 T get() { return old_value; }
29 private:
30 T& X;
31 T old_value;
32 };
33
34 // SaveOr - Similar to SaveAndRestore. Operates only on bools; the old
35 // value of a variable is saved, and during the dstor the old value is
36 // or'ed with the new value.
37 struct SaveOr {
38 SaveOr(bool& x) : X(x), old_value(x) { x = false; }
39 ~SaveOr() { X |= old_value; }
40 private:
41 bool& X;
42 const bool old_value;
43 };
44
45 }
46 #endif
0 //===-- SaveAndRestore.h - Utility -------------------------------*- C++ -*-=//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file provides utility classes that uses RAII to save and restore
10 // values.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_ADT_SAVERESTORE
15 #define LLVM_ADT_SAVERESTORE
16
17 namespace llvm {
18
19 // SaveAndRestore - A utility class that uses RAII to save and restore
20 // the value of a variable.
21 template
22 struct SaveAndRestore {
23 SaveAndRestore(T& x) : X(x), old_value(x) {}
24 SaveAndRestore(T& x, const T &new_value) : X(x), old_value(x) {
25 X = new_value;
26 }
27 ~SaveAndRestore() { X = old_value; }
28 T get() { return old_value; }
29 private:
30 T& X;
31 T old_value;
32 };
33
34 // SaveOr - Similar to SaveAndRestore. Operates only on bools; the old
35 // value of a variable is saved, and during the dstor the old value is
36 // or'ed with the new value.
37 struct SaveOr {
38 SaveOr(bool& x) : X(x), old_value(x) { x = false; }
39 ~SaveOr() { X |= old_value; }
40 private:
41 bool& X;
42 const bool old_value;
43 };
44
45 }
46 #endif