destroy and @safe
Antonio
antonio at abrevia.net
Tue Jun 21 14:40:41 UTC 2022
I'm using explicitly destroy!false(obj) for a "deterministic"
resources release.
I replicate the c# "using" pattern, or the python "with" pattern
with my own "use" template supposing object are RAII
i.e.:
```d
Item[] items = query("...").use( (Answer a) =>
a.rangify.map!(rowToItem).array()
);
```
The problem:
"use" can't be @safe because it contains a call to "destroy".
For better understanding of the idea, I include the "use"
template code
```d
R use(R, T)(T obj, R delegate(T) fT)
{
scope (exit)
destroy!false(obj);
return fT(obj);
}
```
What's the way to ensure @safe using destroy? (if possible)
More information about the Digitalmars-d-learn
mailing list