]> git.saurik.com Git - wxWidgets.git/blame - include/wx/checkeddelete.h
support SDK < 10.6, fixes #14902
[wxWidgets.git] / include / wx / checkeddelete.h
CommitLineData
664e1314
VZ
1///////////////////////////////////////////////////////////////////////////////
2// Name: wx/checkeddelete.h
3// Purpose: wxCHECKED_DELETE() macro
4// Author: Vadim Zeitlin
5// Created: 2009-02-03
6// RCS-ID: $Id$
7// Copyright: (c) 2002-2009 wxWidgets dev team
8// Licence: wxWindows licence
9///////////////////////////////////////////////////////////////////////////////
10
11#ifndef _WX_CHECKEDDELETE_H_
12#define _WX_CHECKEDDELETE_H_
13
4d3845c0
VZ
14#include "wx/cpp.h"
15
664e1314
VZ
16// TODO: provide wxCheckedDelete[Array]() template functions too
17
18// ----------------------------------------------------------------------------
19// wxCHECKED_DELETE and wxCHECKED_DELETE_ARRAY macros
20// ----------------------------------------------------------------------------
21
22/*
23 checked deleters are used to make sure that the type being deleted is really
24 a complete type.: otherwise sizeof() would result in a compile-time error
25
26 do { ... } while ( 0 ) construct is used to have an anonymous scope
27 (otherwise we could have name clashes between different "complete"s) but
28 still force a semicolon after the macro
29*/
30
664e1314 31#define wxCHECKED_DELETE(ptr) \
4d3845c0 32 wxSTATEMENT_MACRO_BEGIN \
664e1314
VZ
33 typedef char complete[sizeof(*ptr)]; \
34 delete ptr; \
4d3845c0 35 wxSTATEMENT_MACRO_END
664e1314
VZ
36
37#define wxCHECKED_DELETE_ARRAY(ptr) \
4d3845c0 38 wxSTATEMENT_MACRO_BEGIN \
664e1314
VZ
39 typedef char complete[sizeof(*ptr)]; \
40 delete [] ptr; \
4d3845c0 41 wxSTATEMENT_MACRO_END
664e1314
VZ
42
43
44#endif // _WX_CHECKEDDELETE_H_
45