From 6706b19af8aeb214a6f234cf09819a659c6cda76 Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Sat, 13 Feb 2016 18:06:35 -0500 Subject: [PATCH] Define macro safenew and template functions std::make_unique --- src/Audacity.h | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/Audacity.h b/src/Audacity.h index 4f5666c55..2c9881f64 100644 --- a/src/Audacity.h +++ b/src/Audacity.h @@ -161,4 +161,34 @@ void QuitAudacity(); // Marks strings for extraction only...must use wxGetTranslation() to translate. #define XO(s) wxT(s) +#include +#include + +// Reviewed, certified, non-leaky uses of new that immediately entrust their results to RAII objects. +// You may use it in new code when constructing a wxWindow subclass with non-NULL parent window. +// You may use it in new code when the new expression is the constructor argument for a standard smart +// pointer like std::unique_ptr or std::shared_ptr. +#define safenew new + +#if !defined(__WXMSW__) +namespace std { +// replicate make_unique, enough for our purposes + +// "scalar" version +template inline + unique_ptr make_unique(Args&&... args) +{ + return (unique_ptr(safenew X(forward(args)...))); +} + +// array version +template inline + unique_ptr make_unique(size_t count) +{ + return (unique_ptr(safenew X[count]())); +} + +} +#endif + #endif // __AUDACITY_H__