From 26b4701ebd2609d9d654350c7e6c109ba8f4bb36 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 17 Sep 2018 23:19:23 +0200 Subject: [PATCH] Define wxShrinkToFit() helper for wxVector<> Unlike member shrink_to_fit(), this function is always defined, even when wxVector is pre-C++11 std::vector<>. --- include/wx/dynarray.h | 7 +------ include/wx/vector.h | 13 +++++++++++++ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/include/wx/dynarray.h b/include/wx/dynarray.h index e6d5178f73..84a65cbce6 100644 --- a/include/wx/dynarray.h +++ b/include/wx/dynarray.h @@ -111,12 +111,7 @@ public: void Shrink() { -#if !wxUSE_STD_CONTAINERS || __cplusplus >= 201103L || wxCHECK_VISUALC_VERSION(10) - this->shrink_to_fit(); -#else - base_vec tmp(*this); - this->swap(tmp); -#endif + wxShrinkToFit(*this); } size_t GetCount() const { return this->size(); } diff --git a/include/wx/vector.h b/include/wx/vector.h index 8a7ae1b228..113157875c 100644 --- a/include/wx/vector.h +++ b/include/wx/vector.h @@ -669,6 +669,19 @@ void wxVectorSort(wxVector& v) #endif // wxUSE_STD_CONTAINERS/!wxUSE_STD_CONTAINERS +// Define vector::shrink_to_fit() equivalent which can be always used, even +// when using pre-C++11 std::vector. +template +inline void wxShrinkToFit(wxVector& v) +{ +#if !wxUSE_STD_CONTAINERS || __cplusplus >= 201103L || wxCHECK_VISUALC_VERSION(10) + v.shrink_to_fit(); +#else + wxVector tmp(v); + v.swap(tmp); +#endif +} + #if WXWIN_COMPATIBILITY_2_8 #define WX_DECLARE_VECTORBASE(obj, cls) typedef wxVector cls #define _WX_DECLARE_VECTOR(obj, cls, exp) WX_DECLARE_VECTORBASE(obj, cls)