【问题标题】:Is there any equivalent std::algorithm similar to std::map::lower_bound for std::tr1::unordered_map?对于 std::tr1::unordered_map,是否有任何等效的 std::algorithm 类似于 std::map::lower_bound?
【发布时间】:2016-08-16 16:43:10
【问题描述】:

对于 std::tr1::unordered_map 是否有任何等效的 std::algorithm 类似于 std::map::lower_bound ?

【问题讨论】:

  • 如果序列是无序的,lower_bound有什么用?
  • 基本上我想在我的代码中使用已经存在的容器,即 std::tr1::unordered_map 而不将其复制到 std::map。
  • 在更高的层次上,你想要完成什么?

标签: c++ algorithm unordered-map


【解决方案1】:

不,没有,因为std::unordered_map 不是有序容器。

std::lower_bound 存在,但它只适用于有序容器:

要求:[first,last) 的元素e 应根据表达式e < valuecomp(e, value) 进行分区。

C++11,[lower.bound] (§25.4.3.1)

【讨论】:

  • std::unordered_map 满足 ForwardIteratorstd::lower_bound 要求其迭代器满足 ForwardIterator。我错过了什么?
  • @Rakete1111:“范围[first, last) 必须至少部分排序,即相对于表达式元素< valuecomp(element, value) 进行分区。完全排序的范围符合此标准,如对std::partition的调用产生一个范围。"
猜你喜欢
  • 1970-01-01
  • 2010-10-22
  • 2012-02-05
  • 2012-10-12
  • 1970-01-01
  • 2020-07-18
  • 1970-01-01
  • 2022-01-13
  • 1970-01-01
相关资源
最近更新 更多