On 2011-09-04 21:34, Andrei Alexandrescu wrote:
On 9/4/11 2:58 PM, Jacob Carlborg wrote:
I'm not sure if this is what you mean but:
File file;
void foo ()
{
scope f = new File;
file = f;
}
void main ()
{
foo;
// file is disposed here
}
In the above example "dispose" will be called when "foo" exits. After
the call to "foo" in the main function "file" will refer to an object
that is disposed, i.e. an object where the "dispose" method has been
called.
I don't know how bad this is or if it is bad at all.
Well it's not bad but a bit underwhelming. Clearly it's better than the
unsafe behavior of scope, but it's nothing to write home about. The
grand save it makes is replacing "scope(exit) f.dispose();" with "scope"
in front of the declaration. That does systematically save some typing,
but it's a feature with only local, non-modular effect, and limited
abstraction power.
Andrei
Yeah, a variable declared as "scope" shouldn't, preferably, exit it's
scope. The compiler will at least complain if you try to return a scoped
variable.
--
/Jacob Carlborg