February 24, 2017 Re: RAII | ||||
---|---|---|---|---|
| ||||
Posted in reply to Arun Chandrasekaran | Arun Chandrasekaran wrote:
> On Thursday, 23 February 2017 at 09:57:09 UTC, ketmar wrote:
>
> Thanks for your help. NRVO looks interesting. However this may not be RAII after all. Or may be too much of C++ has spoiled me. I am not familiar enough with D to appreciate/question the language design choice. I'll accept this and move forward and see how my code evolves. Nevertheless, I'm still learning something new. :)
also, why structs at all? there are another ways! ;-)
void doWithLock (scope void delegate () action) {
lockSomething();
scope(exit) unlockSomething();
action();
}
no, wait, this is not so limiting as it may look!
void foo () {
int i = 42;
doWithLock({
writeln("i=", i); // yay, 42!
});
}
this looks *almost* like `synchronized(obj) { ... }`! and if we'll ever press D devs to allow us to omit "()" when the only argument is arg-less lambda... it will be indistinguishable from built-in! ;-)
|
Copyright © 1999-2021 by the D Language Foundation