Boost logo

Boost :

From: Aleksey Gurtovoy (alexy_at_[hidden])
Date: 2000-02-03 18:24:18


Dave Abrahams <abrahams_at_[hidden]> wrote:
>
> I once designed a more flexible variation on this called set_on_exit,
which
> would assign a value into a reference upon destruction. This lets you
> restore the original value thusly:
>
> boost::set_on_exit<bool> on_exit(flag, flag);
> flag = false;
>
> But also lets you do things like this:
>
> boost::set_on_exit<bool> on_exit(flag, true);
>
> which sets flag to true regardless of its current state when the scope is
> exited. That's useful for things like semaphores (detecting synchronous
> re-entry to a section of code).
>
> Also, even the name temporary_value is not great, IMO, because objects of
> this class do not act as temporary values of their parameter type.
>

It's true.. I've named it 'temporary_value' because I couldn't come to any
better
name ;). It was supposed to reflect the assignment of a new (temporary)
value
to an object in the constructor. But I like your 'set_on_exit' much more -
of
course with the generalization of the class itself. The only thing we lose
with
such generalization is a ability to assign a new value and save an old one
in a
single line of code. But probably this is not a big issue...

- Alexy


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