On Thursday, 23 February 2017 at 09:57:09 UTC, ketmar wrote:
Arun Chandrasekaran wrote:

I'm trying to write an RAII wrapper on Linux.

I understand struct in D doesn't have default constructor (for .init reasons).
I don't want to use `scope`.

Is there an elegant way to achieve this in D?
why not static method or free function that returns struct? due to NRVO[0] it won't even be copied.

 auto lock = MyWrapper();

`MyWrapper()` may return voldemort type, so user won't create your struct accidentally.


[0] https://dlang.org/glossary.html#nrvo

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. :)
  • RAII Arun Chandrasekaran via Digitalmars-d-learn
    • Re: RAII ketmar via Digitalmars-d-learn
      • Re: RAII kinke via Digitalmars-d-learn
        • Re: RAII Adam D. Ruppe via Digitalmars-d-learn
      • Re: RAII Arun Chandrasekaran via Digitalmars-d-learn
        • Re: RAII ketmar via Digitalmars-d-learn
    • Re: RAII Adrian Matoga via Digitalmars-d-learn
    • Re: RAII cym13 via Digitalmars-d-learn
      • Re: RAII Arun Chandrasekaran via Digitalmars-d-learn

Reply via email to