如何解决为什么 std::set::find 不提供提示迭代器?
#include <set>
#include <vector>
using Value = std::vector<int>;
int main()
{
auto coll = std::set<Value>{};
// ......
// Insert many values here.
// ......
auto new_value = Value{1,2,3};
auto const pos = coll.find(new_value);
if (pos != coll.end())
{
// Good
coll.emplace_hint(coll.erase(pos),std::move(new_value));
}
else
{
// Performance penalty!
// No hint here,though coll.find(new_value) kNows that.
coll.emplace(std::move(new_value));
}
}
为什么 std::set::find
不提供提示迭代器?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。