如何在不实际插入的情况下找到元素将插入std::映射的位置

How to find where an element will be inserted into a std::map without actually inserting it

本文关键字:插入 std 位置 映射 元素 不实际 情况下      更新时间:2023-10-16

有没有一种方法可以轻松地找到一个迭代器,在该迭代器中,元素将被插入到std::map中,而无需实际插入元素?

你能做的最好的事情就是使用:

std::map::upper_bound()
std::map::lower_bound()
以获取key大于或大于或等于特定键值的迭代器位置。