What kinds of iterators of C++'s copy function requires? What about reverse or unique?

来源:互联网 发布:超人幻想 知乎 编辑:程序博客网 时间:2024/06/08 01:49

What kinds of iterators of C++'s copy function requires? What about reverse or unique?

STL的Copy:

  • 前两个参数确定源数据的复制范围[first,last)。第三个参数是目标数据的起始位置。
    这里的参数不一定非要是迭代器,也可以是普通的指向数组的指针。
    需要注意的是Copy不支持自复制也就是第三个参数dest所指的位置在[first, last)范围内是不行的。
  • copy : first and second are Input iterators, last is Output iterators.(前两个参数为输入迭代器,只读。最后一个为输出迭代器,只写)
  • reverse : Bidirectional iterators.(双向迭代器)
  • unique : Forward iterators.(前向迭代器)

算法sort要求随机访问迭代器。array、deque、string、vector的迭代器都是随机访问迭代器,用于访问内置数组元素的指针也是。

0 0