Last active
August 29, 2015 14:04
-
-
Save peterix/0b3a5671eb133b38133e to your computer and use it in GitHub Desktop.
A thing that can be default until set. And become default after reset.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| template <typename T, typename D> | |
| class DefaultVariable | |
| { | |
| public: | |
| operator =(const T & value) | |
| { | |
| currentValue = value; | |
| is_default = currentValue == defaultValue; | |
| } | |
| operator const T &() const | |
| { | |
| return is_default ? defaultValue : currentValue; | |
| } | |
| bool isDefault() const | |
| { | |
| return is_default; | |
| } | |
| private: | |
| T currentValue; | |
| T defaultValue = D; | |
| bool is_default = true; | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment