【问题标题】:How to find where an element will be inserted into a std::map without actually inserting it如何在不实际插入的情况下找到将元素插入 std::map 的位置
【发布时间】:2012-02-14 07:21:39
【问题描述】:

有没有办法在不实际插入元素的情况下轻松找到将元素插入std::map 的迭代器?

【问题讨论】:

    标签: c++ dictionary std stdmap c++-standard-library


    【解决方案1】:

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

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

    【讨论】:

    • 值得注意的是,如果您将lower_bound 的结果作为提示传递给insert,您将获得后者的恒定时间性能。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-22
    • 1970-01-01
    • 2020-04-17
    • 1970-01-01
    相关资源
    最近更新 更多