5

我正在迭代 a boost interval_set<unsigned_int>,并且我希望每个迭代器都是 a boost interval,其值将使用upperandlower方法访问:

boost::icl::interval_set<unsigned int> outages;
// ...
// Insert intervals into the database
for(boost::icl::interval_set<unsigned int>::iterator it =
    outages.begin(); it != outages.end(); it++){

    DATA_ACQUISITION::InsertInterval(db, it->lower(),
        it->upper())
}

但是我在方法lowerupper方法上都收到错误:Method ... could not be resolved,这表明迭代器根本没有指向 a interval

那么,我在这里真正迭代的是什么?如何迭代intervals插入到interval_set中?

编辑:添加 SSCCE:

#include <boost/icl/interval_set.hpp>
#include <iostream>
#include <vector>


int main() {
    boost::icl::interval_set<unsigned int> outages;
    for(unsigned int i=0; i<5; i++){
        outages += boost::icl::discrete_interval<unsigned int>::closed(
            (i*10), ((i*10) + 5));
    }

    for(boost::icl::interval_set<unsigned int>::iterator it =
        outages.begin(); it != outages.end(); it++){

        std::cout << it->lower() << boost::icl::upper(*it);
    }
    return 0;
}

附加信息:

  • 我目前没有在链接器中添加任何库(直到现在,没有错误提示我需要它,并且还没有找到应该添加到 -l 的参数)
    • 编译器 g++ 4.8.1
    • 增强版:1.46
4

2 回答 2

9

至少在最新的提升中,这不是问题:

住在科利鲁

#include <boost/icl/interval_set.hpp>
#include <iostream>

int main() {
    typedef boost::icl::interval_set<unsigned int> set_t;
    typedef set_t::interval_type ival;
    set_t outages;

    outages.insert(ival::closed(1,1));
    outages.insert(ival::open(7,10));
    outages.insert(ival::open(8,11));
    outages.insert(ival::open(90,120));

    for(set_t::iterator it = outages.begin(); it != outages.end(); it++){
        std::cout << it->lower() << ", " << it->upper() << "\n";
    }
}

印刷

1, 1
7, 11
90, 120

如果旧的 bo​​ost 版本不直接支持成员,请尝试免费功能:

std::cout << lower(*it) << ", " << upper(*it) << "\n";

在这里,ADL 找到在boost::icl命名空间中声明的重载

于 2015-01-29T22:24:32.520 回答
1

最后,我意识到错误不是来自编译而是来自Eclipse CDT,并且根本没有影响。

于 2015-02-04T11:47:17.083 回答