Dne 27.8.2016 v 02:04 pineapple via Digitalmars-d-learn napsal(a):
I would just love if I could express this as something more like
context(auto file = File("some_file.txt")){
file.write();
}
void main(string[] args)
{
with(File("some_file.txt"))
{
write();
On Saturday, 27 August 2016 at 00:04:47 UTC, pineapple wrote:
context(auto file = File("some_file.txt")){
file.write();
}
You don't need to do anything special for that in D, structs are
destructed automatically. Plain
auto file = File("some_file.txt");
file.write();
will
I would just love if I could express this as something more like
context(auto file = File("some_file.txt")){
file.write();
}
On Friday, 26 August 2016 at 23:30:15 UTC, Cauterite wrote:
On Friday, 26 August 2016 at 23:28:27 UTC, pineapple wrote:
I've grown to very much appreciate how context initialization
and teardown can be very conveniently handled using `with` in
Python. Is there any clean way to imitate this
On Friday, 26 August 2016 at 23:28:27 UTC, pineapple wrote:
I've grown to very much appreciate how context initialization
and teardown can be very conveniently handled using `with` in
Python. Is there any clean way to imitate this syntax in D?
Yep, scope guards.
auto p = OpenProcess(...);