RAII
ketmar via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Feb 23 01:57:09 PST 2017
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
More information about the Digitalmars-d-learn
mailing list