What's the difference between std::advance and std::next?

Tavison picture Tavison · Feb 22, 2013 · Viewed 22.1k times · Source

Is there more beyond advance takes negative numbers?

Answer

Benjamin Lindley picture Benjamin Lindley · Feb 22, 2013

std::advance

  • modifies its argument
  • returns nothing
  • works on input iterators or better (or bi-directional iterators if a negative distance is given)

std::next

  • leaves its argument unmodified
  • returns a copy of the argument, advanced by the specified amount
  • works on forward iterators or better (or bi-directional iterators if a negative distance is given))