Loading...
Searching...
No Matches
TfScopedAutoVar Class Reference

Reset variable on exiting scope. More...

#include <scoped.h>

Public Member Functions

template<typename T >
 TfScopedAutoVar (T &x, const T &val)
 Set/reset variable.
 

Detailed Description

Reset variable on exiting scope.

A TfScopedAutoVar sets a variable to a value when created then restores its original value when destroyed.

For example:

int func(bool x) {
TfScopedAutoVar scope(x, true); // set x to true
return func2(x); // restore x after calling func2
}
Reset variable on exiting scope.
Definition: scoped.h:180

This differs from TfScopedVar in that it's not a template class, the value type is deduced automatically and it allocates memory on the heap. If performance is critical or memory must not be allocated then use TfScopedVar instead.

See also
TfScopedVar

Definition at line 180 of file scoped.h.

Constructor & Destructor Documentation

◆ TfScopedAutoVar()

TfScopedAutoVar ( T &  x,
const T &  val 
)
inlineexplicit

Set/reset variable.

Sets x to val immediately and restores its old value when this goes out of scope.

Definition at line 189 of file scoped.h.


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