Gavin Lambert wrote:
To fix that, you could have the callback return void and take the shared_ptr as a parameter instead -- keeping it alive keeps the file open. The callback would only be called when the framework needs to open a new file (or a new pointer to an existing file), not when re-using an existing pointer.
That's interesting too, but also more involved to implement afaict. The boolean callback is super simple for the client to use, and for the backend to implement. I feel like there should be a solid use case someone would really like solved to prefer the more complicated approaches (making the client responsible for opening the file, or having the client manage lifetime via shared_ptr). I'll admit I'm biased because my use case doesn't require that, but I don't immediately see what such a use case would be.