std :: inserter为std :: set使用.begin()与.end()之间有区别吗? [英] Is there a difference between using .begin() vs .end() for std::inserter for std::set?
问题描述
it1和it2之间是否有区别?
If there is any difference between it1 and it2?
std::set<sometype> s;
auto it1 = std::inserter(s, s.begin());
auto it2 = std::inserter(s, s.end());
推荐答案
在实践中并不多.如果要将大量已有的order元素插入到空的set
中,第二个会更快一些,但是仅此而已. std::insert_iterator
用迭代器调用insert
; std::set
将其解释为提示,如果插入紧接在提示之前,则以恒定时间(而不是lg n)插入. (实际上,如果set
为空,我认为两者都会做完全相同的事情.)
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. std::insert_iterator
calls insert
with the iterator; std::set
interprets it as a hint, and inserts in constant time (rather than lg n) if the insertion is immediately before the hint. (Actually, if the set
is empty, I think both will do exactly the same thing.)
这篇关于std :: inserter为std :: set使用.begin()与.end()之间有区别吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!