#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));
}
}
Why does std::set::find
not provide a hint iterator?
Aucun commentaire:
Enregistrer un commentaire