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
BufferingAudioSource
thedeleteSourceWhenDeleted
parameter doesn’t come right after thesource
parameter that it refers to but there are more arguments in between. - Additionally there are classes like
BufferingAudioReader
which 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
OptionalScopedPointer
instead of the pair of pointer and boolean - Make the casts from
std::unique_ptr
and from references toOptionalScopedPointer
implicit rather than explicit, and additionally make it also support casts fromunique_ptr
of sub-classes. This would make the usage very ergonomic - if you have aunique_ptr
you can juststd::move
it 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