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)