C++ STL advance 和next 区别

advance和next的功能是获取下一个元素,但是这两个操作有一点不同

std::advance

  • modifies its argument
    会修改迭代器本身的值
  • returns nothing
    返回值是void,也就是不返回值
  • 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))

https://stackoverflow.com/questions/15017065/whats-the-difference-between-stdadvance-and-stdnext

posted @ 2019-05-05 20:28  MalcolmMeng  阅读(878)  评论(0编辑  收藏  举报