HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TfScopedAutoVar Class Reference

#include <scoped.h>

Public Member Functions

template<typename T >
 TfScopedAutoVar (T &x, const T &val)
 

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
}

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

template<typename T >
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: