Make sure lifetime of helper structs is less than owning struct
WebFreak001
d.forum at webfreak.org
Mon Nov 15 15:56:57 UTC 2021
I have an API with some struct like a file reader. I want to add
byChunks-like functionality to it, so I'm trying to implement it
with a helper struct that implements opApply. I have disabled
copying the file reader struct because it cleans up the resources
once it goes out of scope, however now I need to temporarily save
the resources in the helper struct to be able to read from it.
How can I make sure that the foreach helper struct (and with that
the copies of the resources) cannot be used once the owning
struct goes out of scope?
```d
ByChunk helper;
{
auto file = FileReader(x);
helper = file.byChunk;
}
helper.popFront; // crash - I want the compiler to disallow this
```
is this currently possible or maybe possible with DIP1000?
More information about the Digitalmars-d-learn
mailing list