我正在迭代boost interval_set<unsigned_int>
,我希望每个迭代器都是boost interval
,其值可以使用upper
和lower
方法访问:
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())
}
但我在lower
和upper
方法都收到错误:方法...无法解析,这表明迭代器未指向完全interval
。
那么,我在这里迭代的是什么?如何迭代插入intervals
_ set?
interval
编辑:添加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;
}
其他信息:
答案 0 :(得分:9)
至少在最近的提升中,这不是问题:
<强> Live On Coliru 强>
#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
如果较旧的boost版本不直接支持成员,请尝试免费功能:
std::cout << lower(*it) << ", " << upper(*it) << "\n";
这里,ADL找到boost::icl
命名空间
答案 1 :(得分:1)
最后,我意识到错误不是来自编译,而是来自Eclipse CDT,并且完全没有效果。