DNDSR 0.1.0.dev1+gcd065ad
Distributed Numeric Data Structure for CFV
Loading...
Searching...
No Matches
DNDS::ScopedValueAlternator< T > Class Template Reference

RAII sentinel: on construction replaces ref with a new value and on destruction restores the original value. More...

#include <ScopedValueAlternator.hpp>

Public Member Functions

template<class TAssign >
 ScopedValueAlternator (T &ref, TAssign &&vAssign)
 Save the current value of ref and overwrite it with vAssign.
 
 ~ScopedValueAlternator ()
 

Detailed Description

template<class T>
class DNDS::ScopedValueAlternator< T >

RAII sentinel: on construction replaces ref with a new value and on destruction restores the original value.

Useful for surgically changing a global / member flag for the duration of a function without adding explicit try/catch cleanup:

{
runDiagnostics();
} // isDebugging restored here, even on exception
RAII sentinel: on construction replaces ref with a new value and on destruction restores the original...
bool isDebugging
Flag consulted by MPIDebugHold and assert_false_info_mpi.
Definition MPI.cpp:90

Move/copy are not declared; an instance must stay in the scope that owns the reference.

Template Parameters
TAny assignable type.

Definition at line 27 of file ScopedValueAlternator.hpp.

Constructor & Destructor Documentation

◆ ScopedValueAlternator()

template<class T >
template<class TAssign >
DNDS::ScopedValueAlternator< T >::ScopedValueAlternator ( T &  ref,
TAssign &&  vAssign 
)
inline

Save the current value of ref and overwrite it with vAssign.

Definition at line 35 of file ScopedValueAlternator.hpp.

◆ ~ScopedValueAlternator()

template<class T >
DNDS::ScopedValueAlternator< T >::~ScopedValueAlternator ( )
inline

Definition at line 40 of file ScopedValueAlternator.hpp.


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