From 8dd01573d4b6931242e8fff0658fd0a370bec7eb Mon Sep 17 00:00:00 2001 From: Simon Rozman Date: Mon, 16 May 2016 20:32:10 +0200 Subject: [PATCH] unique_ptr deleter using LocalFree added --- include/WinStd/Common.h | 56 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/include/WinStd/Common.h b/include/WinStd/Common.h index 78cce066..5b5d9980 100644 --- a/include/WinStd/Common.h +++ b/include/WinStd/Common.h @@ -196,6 +196,62 @@ namespace winstd #endif + /// + /// Deleter for unique_ptr using LocalFree + /// + template struct LocalFree_delete + { + typedef LocalFree_delete<_Ty> _Myt; + + /// + /// Default construct + /// + LocalFree_delete() {} + + /// + /// Construct from another LocalFree_delete + /// + template LocalFree_delete(const LocalFree_delete<_Ty2>&) {} + + /// + /// Delete a pointer + /// + void operator()(_Ty *_Ptr) const + { + LocalFree(_Ptr); + } + }; + + /// + /// Deleter for unique_ptr to array of unknown size using LocalFree + /// + template struct LocalFree_delete<_Ty[]> + { + typedef LocalFree_delete<_Ty> _Myt; + + /// + /// Default construct + /// + LocalFree_delete() {} + + /// + /// Delete a pointer + /// + void operator()(_Ty *_Ptr) const + { + LocalFree(_Ptr); + } + + /// + /// Delete a pointer of another type + /// + template + void operator()(_Other *) const + { + LocalFree(_Ptr); + } + }; + /// /// \defgroup WinStdSysHandles System Handles /// Simplifies work with object handles of various type