ScopedTemporaryValue< T > Class Template Reference

Back to the index.

Public Member Functions | List of all members
ScopedTemporaryValue< T > Class Template Reference

Scoped temporary variable template. More...

#include <ScopedTemporaryValue.h>

Public Member Functions

 ScopedTemporaryValue (T &var)
 Constructor, which reads the old value from T, but does not change it. More...
 
 ScopedTemporaryValue (T &var, T newValue)
 Constructor, which reads the old value from T, and sets it to a new (temporary) value. More...
 
 ~ScopedTemporaryValue ()
 Destructor, which restores the original value. More...
 

Detailed Description

template<class T>
class ScopedTemporaryValue< T >

Scoped temporary variable template.

Usage:

SomeType var = A;
{
     ScopedTemporaryValue<SomeType> holder(var);
     var = B;
     ...
}
// var will here be reset to A.

or

SomeType var = A;
{
     ScopedTemporaryValue<SomeType> holder(var, B);
     // Here,  var is B.
     ...
}
// var will here be reset to A.

Implementation note: This is just a schoolbook-style implementation of a class which holds a variable, and then restores the original value when going out of scope.

Definition at line 59 of file ScopedTemporaryValue.h.

Constructor & Destructor Documentation

◆ ScopedTemporaryValue() [1/2]

template<class T >
ScopedTemporaryValue< T >::ScopedTemporaryValue ( T &  var)
inline

Constructor, which reads the old value from T, but does not change it.

Parameters
varThe variable.

Definition at line 72 of file ScopedTemporaryValue.h.

◆ ScopedTemporaryValue() [2/2]

template<class T >
ScopedTemporaryValue< T >::ScopedTemporaryValue ( T &  var,
newValue 
)
inline

Constructor, which reads the old value from T, and sets it to a new (temporary) value.

Parameters
varThe variable.
newValueThe new (temporary) value.

Definition at line 85 of file ScopedTemporaryValue.h.

◆ ~ScopedTemporaryValue()

template<class T >
ScopedTemporaryValue< T >::~ScopedTemporaryValue ( )
inline

Destructor, which restores the original value.

Definition at line 95 of file ScopedTemporaryValue.h.


The documentation for this class was generated from the following file:

Generated on Tue Aug 25 2020 19:25:06 for GXemul by doxygen 1.8.18