std::map insert or std::map find?

后端 未结 8 1388
青春惊慌失措
青春惊慌失措 2020-12-12 08:41

Assuming a map where you want to preserve existing entries. 20% of the time, the entry you are inserting is new data. Is there an advantage to doing std::map::find then std

8条回答
  •  孤街浪徒
    2020-12-12 09:04

    I don't seem to have enough points to leave a comment, but the ticked answer seems to be long winded to me - when you consider that insert returns the iterator anyway, why go searching lower_bound, when you can just use the iterator returned. Strange.

提交回复
热议问题