diff --git a/include/wx/propgrid/propgriddefs.h b/include/wx/propgrid/propgriddefs.h index 6eebf00177..91ee22a8c5 100644 --- a/include/wx/propgrid/propgriddefs.h +++ b/include/wx/propgrid/propgriddefs.h @@ -24,6 +24,10 @@ #include "wx/longlong.h" #include "wx/clntdata.h" +#if wxUSE_STD_CONTAINERS +#include +#endif // wxUSE_STD_CONTAINERS + // ----------------------------------------------------------------------- // @@ -760,6 +764,20 @@ inline void wxPGRemoveItemFromVector(wxVector& vector, const T& item) #endif // wxUSE_STL/!wxUSE_STL } +// Utility to calaculate sum of all elements of the vector. +template +inline T wxPGGetSumVectorItems(const wxVector& vector, T init) +{ +#if wxUSE_STD_CONTAINERS + return std::accumulate(vector.begin(), vector.end(), init); +#else + for (typename wxVector::const_iterator it = vector.begin(); it != vector.end(); ++it) + init += *it; + + return init; +#endif // wxUSE_STD_CONTAINERS/!wxUSE_STD_CONTAINERS +} + // ----------------------------------------------------------------------- #endif // wxUSE_PROPGRID diff --git a/src/propgrid/propgridpagestate.cpp b/src/propgrid/propgridpagestate.cpp index f894b6fd0c..d53e1ac4de 100644 --- a/src/propgrid/propgridpagestate.cpp +++ b/src/propgrid/propgridpagestate.cpp @@ -1015,9 +1015,7 @@ void wxPropertyGridPageState::CheckColumnWidths( int widthChange ) m_width, clientWidth); - int colsWidth = pg->GetMarginWidth(); - for (wxVector::const_iterator it = m_colWidths.begin(); it != m_colWidths.end(); ++it) - colsWidth += *it; + int colsWidth = wxPGGetSumVectorItems(m_colWidths, pg->GetMarginWidth()); wxLogTrace("propgrid", wxS(" HasVirtualWidth: %i colsWidth: %i"), @@ -1144,9 +1142,7 @@ void wxPropertyGridPageState::CheckColumnWidths( int widthChange ) void wxPropertyGridPageState::ResetColumnSizes( int setSplitterFlags ) { // Calculate sum of proportions - int psum = 0; - for (wxVector::const_iterator it = m_columnProportions.begin(); it != m_columnProportions.end(); ++it) - psum += *it; + int psum = wxPGGetSumVectorItems(m_columnProportions, 0); int puwid = (m_pPropGrid->m_width*256) / psum; int cpos = 0;