Boost logo

Boost :

From: Sérgio Vale e Pace (svpace.forum_at_[hidden])
Date: 2005-03-15 08:07:47


> > template < typename T >
> > struct auto_set
> > {
> > T & var; T val;
> > auto_set ( T & var, T val ) :
>
> auto_set(T & var,T val = T()):
> // allows one to just specify a variable to be auto-set back to its default
> value also
> > var ( var ), val ( val ) { }

// IMHO I thing it´s more often useful to use var own value to be
restored later:
auto_set(T& var) : var(var), val(var) { }

> > ~ auto_set ( ) { var = val; }
> > };
>


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk