[EMAIL PROTECTED] (Lars Gullik Bjønnes) writes: | Alfredo Braunstein <[EMAIL PROTECTED]> writes: > | | Comments? > | I think it looks good. So if you have no regressions... > | | int numberOfSeparators(Paragraph const & par, Row const & row) | | { | | - pos_type const last = lastPos(par, row); | | + pos_type const first = max(row.pos(), par.beginningOfBody()); | | + pos_type const last = row.endpos() - 1; | | int n = 0; | | - pos_type p = max(row.pos(), par.beginningOfBody()); | | - for ( ; p < last; ++p) | | + for (pos_type p = first; p < last; ++p) { | | if (par.isSeparator(p)) | | ++n; | | + } > | I wonder if std::count could be used here :-)
int numberOfSeparators(Paragraph const & par, Row const & row) { typedef counting_iterator_generator<int>::type CountIt; CountIt first(max(row.pos(), par.beginningOfBody())); CountIt last(lastPos(par, row)); return std::count_if(first, last, bind(&Paragraph::isSeparator, &par, _1)); } or something very similar. What I like about it, is that is very clear that it is counting that is being done. -- Lgb