std :: inserter为std :: set使用.begin()与.end()之间有区别吗? [英] Is there a difference between using .begin() vs .end() for std::inserter for std::set?

查看:704
本文介绍了std :: inserter为std :: set使用.begin()与.end()之间有区别吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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用迭代器调用insertstd::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屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆