JUCE has several (6 that I found at least) classes whose constructors take delete...WhenDeleted arguments, and most implement it with OptionalScopedPointer internally.
- Sometimes, like in
BufferingAudioSourcethedeleteSourceWhenDeletedparameter doesn’t come right after thesourceparameter that it refers to but there are more arguments in between. - Additionally there are classes like
BufferingAudioReaderwhich just take the ownership but it’s unclear why those are different.
I would like to suggest what I think is an improvement to the interface:
- Change these classes to take an
OptionalScopedPointerinstead of the pair of pointer and boolean - Make the casts from
std::unique_ptrand from references toOptionalScopedPointerimplicit rather than explicit, and additionally make it also support casts fromunique_ptrof sub-classes. This would make the usage very ergonomic - if you have aunique_ptryou can juststd::moveit into arguments to juce classes. Or you can even usestd::make_unique<Stuff>right in the arguments.
I also made a branch to demonstrate these changes.
Cheers, Yair

