Skip to content

Instantly share code, notes, and snippets.

@peterix
Last active August 29, 2015 14:04
Show Gist options
  • Select an option

  • Save peterix/0b3a5671eb133b38133e to your computer and use it in GitHub Desktop.

Select an option

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.
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