|
Boost : |
From: Beman Dawes (beman_at_[hidden])
Date: 2000-02-06 13:53:55
At 08:03 AM 2/6/00 -0800, Darin Adler wrote:
>> auto_restore is no good if you're not restoring the value to its
original.
>> What's wrong with set_on_exit, I wonder? Just that it doesn't use
"auto_" in
>> its name? It is perfectly descriptive, I think.
>
>I think that the name "set_on_exit" gives the wrong emphasis.
>
>For similar reasons, I think that "auto_restore" is not such a good
name
>either, despite what I said in my last message.
>
>I think of these objects as a way to safely set a variable to a
value for a
>given scope. The fact that the variable is set back to the old value
at the
>end of the scope is kind of a "detail of implementation", in a way.
I don't
>think of auto_ptr as a "delete on exit" or auto-destroyer; I think
of it as
>a way to represent a pointer to an object with controlled lifetime.
I don't
>focus on the end of lifetime, even though that's where the work of
>destroying the object takes place.
>
>That's why I prefer the class that changes the value and changes it
back to
>the form that just sets a value on exit.
>
>Some others want classes that do arbitrary actions at the end of a
block.
>But I think those are harder to use. For example, I prefer a class
that
>represents an open file to one that closes a file when it falls out
of
>scope, etc.
>
>So I think the name should specify what the class does as a whole
(change
>the value of a variable for a particular scope, but change it back
when the
>scope ends) rather than just focusing on what it does at the end of
the
>scope. I still think that the "auto_" prefix might be a good idea.
Maybe
>"auto_value_changer" or "auto_value_setter".
Hum... You are right... It is like scoped_ptr rather than auto_ptr.
So call it scoped_restore or scoped_value_changer or
scoped_value_setter.
--Beman
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk