Cbeam
Loading...
Searching...
No Matches
cbeam::lifecycle::scoped_set< T > Class Template Reference

A helper that sets the given variable to a new value, and restores the original value on destruction. More...

#include <scoped_set.hpp>

Public Types

using ValueType = typename extract_atomic_value_type<T>::type
 

Public Member Functions

 scoped_set (T &instance, ValueType newVal)
 Constructs a scoped_set and assigns newVal to instance.
 
virtual ~scoped_set () noexcept
 Destructor that restores the original value of the managed variable.
 

Detailed Description

template<typename T>
class cbeam::lifecycle::scoped_set< T >

A helper that sets the given variable to a new value, and restores the original value on destruction.

This class can handle both normal and std::atomic variables. On construction, it stores the old value, then sets the variable to the new value. On destruction, it reverts the variable back to the original value.

Template Parameters
TThe type of the managed variable (normal or atomic).

Member Typedef Documentation

◆ ValueType

template<typename T>
using cbeam::lifecycle::scoped_set< T >::ValueType = typename extract_atomic_value_type<T>::type

Constructor & Destructor Documentation

◆ scoped_set()

template<typename T>
cbeam::lifecycle::scoped_set< T >::scoped_set ( T & instance,
ValueType newVal )
inline

Constructs a scoped_set and assigns newVal to instance.

Stores the previous value, which is restored on destruction.

Parameters
instanceA reference to the variable to manage.
newValThe new value to set temporarily.

◆ ~scoped_set()

template<typename T>
virtual cbeam::lifecycle::scoped_set< T >::~scoped_set ( )
inlinevirtualnoexcept

Destructor that restores the original value of the managed variable.


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