简体   繁体   中英

Why does the C++ std::unordered_map returning an iterator from emplace / find?

I understand why an unordered_map has an iterator (begin() and end()) but I don't see what value returning an iterator from find / emplace is.

I can't imagine a use case where you would want to start your iterator at a given key as opposed to begin / end (because a good hash function should make the position of a key in the table arbitrary).

The alternative; to just return the value, reference to the value, or pair of key and value covers all use cases I can imagine an avoids the unnecessary work of creation an iterator and likely causing an additional memory deference when using it to access the underlying pair / value.

What if you want to remove the item? What if you want to extract or merge it? What if you want to use it as a hint to emplace?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM