From 0e99ab2c495f3e5492d50bd21b6a96c634b7aa0e Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 1 Jun 2018 18:13:35 +0200 Subject: [PATCH] Use template functions instead of WX_XXX_ARRAY() macros Trivially rewrite macros as functions. No real changes. --- include/wx/dynarray.h | 55 +++++++++++++++++++++++-------------------- 1 file changed, 29 insertions(+), 26 deletions(-) diff --git a/include/wx/dynarray.h b/include/wx/dynarray.h index 94cd430ef4..fa52765dd3 100644 --- a/include/wx/dynarray.h +++ b/include/wx/dynarray.h @@ -864,32 +864,34 @@ WX_DEFINE_USER_EXPORTED_ARRAY_LONG(long, wxArrayLong, class WXDLLIMPEXP_BASE); WX_DEFINE_USER_EXPORTED_ARRAY_PTR(void *, wxArrayPtrVoid, class WXDLLIMPEXP_BASE); // ----------------------------------------------------------------------------- -// convenience macros +// convenience functions: they used to be macros, hence the naming convention // ----------------------------------------------------------------------------- // prepend all element of one array to another one; e.g. if first array contains // elements X,Y,Z and the second contains A,B,C (in those orders), then the // first array will be result as A,B,C,X,Y,Z -#define WX_PREPEND_ARRAY(array, other) \ - { \ - size_t wxAAcnt = (other).size(); \ - (array).reserve(wxAAcnt); \ - for ( size_t wxAAn = 0; wxAAn < wxAAcnt; wxAAn++ ) \ - { \ - (array).Insert((other)[wxAAn], wxAAn); \ - } \ +template +inline void WX_PREPEND_ARRAY(A1& array, const A2& other) +{ + const size_t size = other.size(); + array.reserve(size); + for ( size_t n = 0; n < size; n++ ) + { + array.Insert(other[n], n); } +} // append all element of one array to another one -#define WX_APPEND_ARRAY(array, other) \ - { \ - size_t wxAAcnt = (other).size(); \ - (array).reserve(wxAAcnt); \ - for ( size_t wxAAn = 0; wxAAn < wxAAcnt; wxAAn++ ) \ - { \ - (array).push_back((other)[wxAAn]); \ - } \ +template +inline void WX_APPEND_ARRAY(A1& array, const A2& other) +{ + size_t size = other.size(); + array.reserve(size); + for ( size_t n = 0; n < size; n++ ) + { + array.push_back(other[n]); } +} // delete all array elements // @@ -897,15 +899,16 @@ WX_DEFINE_USER_EXPORTED_ARRAY_PTR(void *, wxArrayPtrVoid, class WXDLLIMPEXP_BASE // place where you use this macro, otherwise the proper destructor may not // be called (a decent compiler should give a warning about it, but don't // count on it)! -#define WX_CLEAR_ARRAY(array) \ - { \ - size_t wxAAcnt = (array).size(); \ - for ( size_t wxAAn = 0; wxAAn < wxAAcnt; wxAAn++ ) \ - { \ - delete (array)[wxAAn]; \ - } \ - \ - (array).clear(); \ +template +inline void WX_CLEAR_ARRAY(A& array) +{ + size_t size = array.size(); + for ( size_t n = 0; n < size; n++ ) + { + delete array[n]; } + array.clear(); +} + #endif // _DYNARRAY_H