对std::inserter对std::set使用.begin()和.end()有区别吗?
Is there a difference between using .begin() vs .end() for std::inserter for std::set?
如果it1和it2有什么不同?
std::set<sometype> s;
auto it1 = std::inserter(s, s.begin());
auto it2 = std::inserter(s, s.end());
实际上并不多。如果你要在一个空的set
中插入大量已经有序的元素,第二种方法会快一些,但仅此而已。std::insert_iterator
用迭代器调用insert
;std::set
将其解释为提示,如果插入在提示之前,则以常数时间(而不是lgn)插入。(实际上,如果set
是空的,我认为两者将做完全相同的事情。)
From http://www.sgi.com/tech/stl/insert_iterator.html
对于排序关联容器,insert_iterator的构造函数中的迭代器几乎是无关的。新元素不一定会形成一个连续的范围;它们将以键升序出现在容器中的适当位置。它们插入的顺序只影响效率:将已经排序的范围插入排序关联容器是一个O(N)操作。
相关文章:
- 来自 std::list 的迭代器 .end() 按预期返回"0xcdcdcdcdcdcdcdcd"但 .begin()
- std::map<struct,struct>::find 找不到匹配项,但是如果我循环通过 begin() 到 end(),我在那里看到匹配项
- std::multimap<std::chrono::milliseconds, T>::rbegin 在 MSVS-13 中指向 end()?
- 为什么std::begin()和std::end()适用于固定数组,而不适用于动态数组
- 重载 std::begin() 和 std::end() 用于非数组
- std::begin() 和 std::end() 不适用于类中的未知长度数组
- std::end and std::begin in a function (C++)
- 依靠 ADL 实现 std::begin() 和 std::end()
- std::end(myVector) 和 myVector.end() 之间的区别
- 使用 std::begin 和 std::end 进行向量初始化
- 使用 std::begin() 和 std::end() 从数组构造向量
- 我可以专门使用 std::begin 和 std::end 来获取 equal_range() 的返回值吗?
- std::begin 和 std::end 不使用指针并参考原因
- 使用std::begin()、std::end()将ArrayXd转换为stl向量,
- 字符串的std::end应该指向null终止符之后
- 带有std::begin()、std::end()问题的C++11自动迭代器类型
- std::begin和std::end的const重载的目的是什么
- std::end 如何知道数组的结尾
- 在c++中,对于所有容器类型,std::end都保证为0(1)
- 没有c++ 11如何使用std::begin和std::end ?