迭代 boost::icl::interval_set
Iterating boost::icl::interval_set
我正在迭代一个 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
。
那么,我在这里真正迭代的是什么?如何遍历插入 interval
_set 的 intervals
?
编辑:添加 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
至少在最新的提升中,这不是问题:
#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
命名空间
中声明的重载
最后,我意识到错误不是来自编译而是来自 Eclipse CDT,并且根本没有影响。
我正在迭代一个 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
。
那么,我在这里真正迭代的是什么?如何遍历插入 interval
_set 的 intervals
?
编辑:添加 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
至少在最新的提升中,这不是问题:
#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
命名空间
最后,我意识到错误不是来自编译而是来自 Eclipse CDT,并且根本没有影响。