Define wxShrinkToFit() helper for wxVector<>

Unlike member shrink_to_fit(), this function is always defined, even
when wxVector is pre-C++11 std::vector<>.
This commit is contained in:
Vadim Zeitlin
2018-09-17 23:19:23 +02:00
parent 0fd8ec0fa2
commit 26b4701ebd
2 changed files with 14 additions and 6 deletions

View File

@@ -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(); }

View File

@@ -669,6 +669,19 @@ void wxVectorSort(wxVector<T>& 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<typename T>
inline void wxShrinkToFit(wxVector<T>& v)
{
#if !wxUSE_STD_CONTAINERS || __cplusplus >= 201103L || wxCHECK_VISUALC_VERSION(10)
v.shrink_to_fit();
#else
wxVector<T> tmp(v);
v.swap(tmp);
#endif
}
#if WXWIN_COMPATIBILITY_2_8
#define WX_DECLARE_VECTORBASE(obj, cls) typedef wxVector<obj> cls
#define _WX_DECLARE_VECTOR(obj, cls, exp) WX_DECLARE_VECTORBASE(obj, cls)