简体   繁体   中英

Iterating boost::icl::interval_set

I am iterating a boost interval_set<unsigned_int> , and I was expecting each iterator to be a boost interval , whose values would be accessed with the upper and lower methods:

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())
}

But I am receiving errors at both lower and upper methods: Method ... could not be resolved , which suggests me that the iterator is not pointing to an interval at all.

So, what am I really iterating here? How to iterate though the intervals inserted into the interval _set?

EDIT: Adding 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;
}

Additional info:

  • I am currently not adding any library ti the linker (until now, no error suggested I needed that, and haven't found which argument should I add to the -l anyway)
    • Compiler g++ 4.8.1
    • Boost version: 1.46

In latest boost, at least, this is no issue:

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";
    }
}

Prints

1, 1
7, 11
90, 120

If older boost versions don't directly support the members, try the free functions:

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

Here, ADL finds the overloads declared in the boost::icl namespace

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM