Move repeating code to the dedicated template wxVector function

This commit is contained in:
Artur Wieczorek
2018-12-27 11:49:43 +01:00
parent 7d43ed0fb6
commit 9b7c281e6b
2 changed files with 20 additions and 6 deletions

View File

@@ -24,6 +24,10 @@
#include "wx/longlong.h"
#include "wx/clntdata.h"
#if wxUSE_STD_CONTAINERS
#include <numeric>
#endif // wxUSE_STD_CONTAINERS
// -----------------------------------------------------------------------
//
@@ -760,6 +764,20 @@ inline void wxPGRemoveItemFromVector(wxVector<T>& vector, const T& item)
#endif // wxUSE_STL/!wxUSE_STL
}
// Utility to calaculate sum of all elements of the vector.
template<typename T>
inline T wxPGGetSumVectorItems(const wxVector<T>& vector, T init)
{
#if wxUSE_STD_CONTAINERS
return std::accumulate(vector.begin(), vector.end(), init);
#else
for (typename wxVector<T>::const_iterator it = vector.begin(); it != vector.end(); ++it)
init += *it;
return init;
#endif // wxUSE_STD_CONTAINERS/!wxUSE_STD_CONTAINERS
}
// -----------------------------------------------------------------------
#endif // wxUSE_PROPGRID