【问题标题】:Move elements from std::multiset从 std::multiset 移动元素
【发布时间】:2017-05-16 03:50:48
【问题描述】:

是否可以将元素移出 std::multiset?

从 C++11 开始,std::multiset::iterator 被定义为 const bidirectional_iterator。我知道原因是为了保持元素排序,但似乎没有办法删除然后修改仅移动对象。

【问题讨论】:

  • 类似extract 但对于c++11 ?
  • 啊,是的,可惜它是 C++17。
  • 可能是 c++11 中的一个疏忽,不确定你有没有其他选择 =\

标签: c++11 constants move multiset


【解决方案1】:

我不认为你可以用 std::multiset 做到这一点,尽管它应该可以用 Boost 的 multi_index_container 来实现。它有一个 modify() 方法,它接受一个迭代器和一个更新器仿函数。在该函子中,您应该能够将值移走。

详情见Boost multi_index documentation

【讨论】:

    猜你喜欢
    • 2014-11-04
    • 2012-03-05
    • 2014-02-02
    • 2021-12-23
    • 1970-01-01
    • 2012-10-23
    • 2015-08-01
    • 2012-12-12
    • 1970-01-01
    相关资源
    最近更新 更多