Since emplace_hint
method of set / map returns only an iterator figuring out whether item has been actually added is not as convenient as when using emplace
or insert
. Right now I just get container size before / after and compare them:
::std::map<int, int> items{};
const auto initial_items_count{items.size()};
const auto it_item{items.emplace_hint(items.begin(), 0, 5)};
if(items.size() != initial_items_count)
{
// perform additional actions...
}
It can be wrapped up into a helper returning pair, but maybe there is an existing simpler approach?
Aucun commentaire:
Enregistrer un commentaire