JUCE has several (6 that I found at least) classes whose constructors take
delete...WhenDeleted arguments, and most implement it with
- Sometimes, like in
deleteSourceWhenDeletedparameter doesn’t come right after the
sourceparameter 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 to
OptionalScopedPointerimplicit rather than explicit, and additionally make it also support casts from
unique_ptrof sub-classes. This would make the usage very ergonomic - if you have a
unique_ptryou can just
std::moveit into arguments to juce classes. Or you can even use
std::make_unique<Stuff>right in the arguments.
I also made a branch to demonstrate these changes.