Does D have any construct like Python's with keyword?

Cauterite via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Aug 26 16:30:15 PDT 2016


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(...);
scope(exit) {CloseHandle(p);};


More information about the Digitalmars-d-learn mailing list