简体   繁体   English

使用.begin()和.end()对于std :: set的std :: inserter有区别吗?

[英]Is there a difference between using .begin() vs .end() for std::inserter for std::set?

If there is any difference between it1 and it2? 如果it1和it2之间有什么区别?

std::set<sometype> s;

auto it1 = std::inserter(s, s.begin());
auto it2 = std::inserter(s, s.end());

In practice, not much. 在实践中,并不多。 If you're inserting a large number of already in order elements into an empty set , the second will be somewhat faster, but that's about it. 如果你将大量已经在订单元素中插入到空set ,那么第二个元素会更快,但这就是它。 std::insert_iterator calls insert with the iterator; std::insert_iterator使用迭代器调用insert ; std::set interprets it as a hint, and inserts in constant time (rather than lg n) if the insertion is immediately before the hint. std::set将其解释为提示,并且如果插入位于提示之前,则以恒定时间(而不是lg n)插入。 (Actually, if the set is empty, I think both will do exactly the same thing.) (实际上,如果该set是空的,我认为两者都会完全相同。)

From http://www.sgi.com/tech/stl/insert_iterator.html 来自http://www.sgi.com/tech/stl/insert_iterator.html

In the case of a Sorted Associative Container, however, the iterator in the insert_iterator's constructor is almost irrelevant. 但是,在Sorted Associative Container的情况下,insert_iterator的构造函数中的迭代器几乎不相关。 The new elements will not necessarily form a contiguous range; 新元素不一定会形成连续的范围; they will appear in the appropriate location in the container, in ascending order by key. 它们将按键按升序显示在容器中的适当位置。 The order in which they are inserted only affects efficiency: inserting an already-sorted range into a Sorted Associative Container is an O(N) operation. 它们的插入顺序仅影响效率:将已排序的范围插入到排序关联容器中是O(N)操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM