c++ - boost::flat_set 的迭代器无法合并

标签 c++ boost iterator c++17

我正在尝试将 boost::flat_set 用于我要求唯一的小型迭代器集。代码无法编译,因为对 make_reverse_iterator 的调用不明确,但我不确定它是如何发生的。我试图将问题减少到 MWE:

#include <boost/container/flat_set.hpp>
#include <set>
#include <iostream>

using Set = std::set<int>;
using SetIt = Set::iterator;

struct Comparator {
    bool operator()(SetIt lhs, SetIt rhs) const {
        return &(*lhs) < &(*rhs);
    }
};


int main() {
    std::set<int> x;
    boost::container::flat_set<Set::iterator, Comparator> a;
    boost::container::flat_set<Set::iterator, Comparator> b;

    a.insert(x.insert(1).first);
    a.insert(x.insert(2).first);
    a.insert(x.insert(3).first);
    a.insert(x.insert(4).first);
    a.insert(x.insert(5).first);

    b.insert(x.insert(3).first);
    b.insert(x.insert(4).first);
    b.insert(x.insert(5).first);
    b.insert(x.insert(6).first);
    b.insert(x.insert(7).first);

    a.merge(b);

    for (auto v : a)
        std::cout << *v << '\n';
    return 0;
}

最佳答案

这个问题显然是 fixed in Boost 1.67 .

我在 fixed in Boost 1.66 上重现了错误.

关于c++ - boost::flat_set 的迭代器无法合并,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51928329/

相关文章:

c++ - 如何使用 std::find 作为类 vector ?

c++ - 简单 boost 序列化中的未定义引用错误

c++ - 我能否获取模板类型的 "iterator",无论该类型是数组还是类似 STL 的容器?

python - 列表字典的笛卡尔积 - 带排序

python - 循环链表代码陷入无限循环

c++ - c++中如何读入一个文件并垂直显示内容,然后读入另一个文件并垂直显示内容

模板化类的模板化构造函数的 C++ 显式模板特化

c++ - 多态性并在C++中定义不同对象的列表

c++ - 增加访问量可能存在错误

c++ - boost 中的子图和图连通性