-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathToggle.h
More file actions
31 lines (24 loc) · 673 Bytes
/
Copy pathToggle.h
File metadata and controls
31 lines (24 loc) · 673 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/** $VER: Toggle.h (2026.07.22) P. Stuer - Adaped from foobar2000 SDK **/
#pragma once
#pragma once
/// <summary>
/// Implements a toggle that returns a variable to its previous value when the toggle goes out of scope.
/// </summary>
template<typename T> class toggle_t
{
public:
template<typename U> toggle_t(T & variable, U && value) : _Variable(variable)
{
_OldValue = std::move(_Variable);
_Variable = std::forward<U>(value);
}
toggle_t(const toggle_t &) = delete;
void operator=(const toggle_t &) = delete;
~toggle_t()
{
_Variable = std::move(_OldValue);
}
private:
T & _Variable;
T _OldValue;
};