1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-08-16 08:34:10 +02:00

Define Destroy_ptr

This commit is contained in:
Paul Licameli 2016-08-09 22:40:21 -04:00
parent 384fc4a4ae
commit aaeaadff07

View File

@ -688,6 +688,22 @@ make_movable_with_deleter(const Deleter &d, Args&&... args)
return movable_ptr_with_deleter<T, Deleter>(safenew T(std::forward<Args>(args)...), d);
}
/*
* A deleter class to supply the second template parameter of unique_ptr for
* classes like wxWindow that should be sent a message called Destroy rather
* than be deleted directly
*/
template <typename T>
struct Destroyer {
void operator () (T *p) const { if (p) p->Destroy(); }
};
/*
* a convenience for using Destroyer
*/
template <typename T>
using Destroy_ptr = std::unique_ptr<T, Destroyer<T>>;
/*
* "finally" as in The C++ Programming Language, 4th ed., p. 358
* Useful for defining ad-hoc RAII actions.