monotone-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Monotone-devel] set's erase() and iterators


From: Markus Schiltknecht
Subject: Re: [Monotone-devel] set's erase() and iterators
Date: Tue, 16 Oct 2007 23:14:34 +0200
User-agent: Icedove 1.5.0.10 (X11/20070328)

Hi,

Václav Haisman wrote:
Markus Schiltknecht wrote, On 16.10.2007 21:33:
One option to circumvent that problem is recreating the set, as I did
for project.cc now. Another option might be using the STL algorithm
remove_if().
I think that you cannot use std::remove_if() on std::set<> since it is not a
sequence as the standard understands the term.

Hm.. yeah, that might be right.

And recreating the whole set
seems wasteful. Instead you could rewrite the loop into while() loop and use
something like

while (it != set.end ())
{
  if (condition ())
  {
    iterator tmp_it = it++;
    set.erase (tmp_it);
    continue;
  }

  // more code

  ++it;
}

Cool. I updated the code again. It now looks like:

  suspended_in_branch s(app, branch_encoded);
  std::set<revision_id>::iterator it = branch.second.begin();
  while (it != branch.second.end())
    if (s(*it))
      branch.second.erase(it++);
    else
      it++;

That might be a little harder to read, but it's short and cute ;-)

Thanks for the hint.

Markus





reply via email to

[Prev in Thread] Current Thread [Next in Thread]