A FlagSaver object stores the state of flags in the scope where the FlagSaver is defined, allowing modification of those flags within that scope and automatic restoration of the flags to their previous state upon leaving the scope.
Declared in <absl/flags/reflection.h>
class FlagSaver;
A FlagSaver can be used within tests to temporarily change the test environment and restore the test case to its previous state.
Example:
void MyFunc() { absl::FlagSaver fs; ... absl::SetFlag(&FLAGS_myFlag, otherValue); ... } // scope of FlagSaver left, flags return to previous state
This class is thread-safe.
| Name | Description |
|---|---|
FlagSaver [constructor] | Constructors |
~FlagSaver [destructor] | Restores all flags to the state saved at construction. |
operator= [deleted] | Not assignable. |