Boost logo

Boost :

From: Edward Diener (eddielee_at_[hidden])
Date: 2005-03-15 11:11:11


Sérgio Vale e Pace wrote:
>>> 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; }
>>> };

Good point ! I agree. We then need two constructors, with the one not taking
a value resetting the variable back to its initial value.


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