MakeVarSetter() relies on the compiler always using RVO, as
VariableSetterImpl<> doesn't have correct copy ctor; worse yet, its use
wasn't detected at compile time. With some compilers (e.g. VC++ 2008
with non-trivial variable types), this resulted in the variable being
reset too soon, immediately in the place where the macro was used.
Fixed by using the same technique already used in wxScopeGuardImpl. In
fact, VariableSetterImpl is just another special case of
wxScopeGuardImpl, so just derive from the latter.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@67592
c3d73ce0-8a6f-49c7-b76d-
6d57e0e08775
{
// empty class just to be able to define a reference to it
-class VariableSetterBase { };
+class VariableSetterBase : public wxScopeGuardImplBase { };
typedef const VariableSetterBase& VariableSetter;
{
}
- ~VariableSetterImpl()
- {
- m_var = m_value;
- }
+ ~VariableSetterImpl() { wxPrivateOnScopeExit(*this); }
+
+ void Execute() { m_var = m_value; }
private:
T& m_var;
{
}
- ~VariableNullerImpl()
- {
- m_var = NULL;
- }
+ ~VariableNullerImpl() { wxPrivateOnScopeExit(*this); }
+
+ void Execute() { m_var = NULL; }
private:
T& m_var;