5

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
Roman Rdgz
  • 12,836
  • 41
  • 131
  • 207
  • I'd reinstall / manually install boost. I've compiled the SSCCE fine with GCC 4.8.2 and boost from `wget http://sourceforge.net/projects/boost/files/boost/1.46.0/boost_1_46_0,1.tar.bz2` (as well 1_47_1). – sehe Jan 30 '15 at 08:41
  • @sehe Have reinstalled 1_46_0, but still the same problem than before with the version from Ubuntu 12.04 repo. it->lowers throws error 'Method lower could not be resolved', and boost::icl::upper(*it) throws 'invalid arguments', and suggests as candidates 'boost:enable::if, bost::icl::inverval_traits<#0>::domain_type::type upper(const #0 &)', and other similar choices which don't see related. This is strange, what shall I try next? – Roman Rdgz Feb 02 '15 at 15:57
  • Recommendation stays the same. It doesn't make sense that you're seeing different source with same version. Try to print the boost version: http://coliru.stacked-crooked.com/a/f7a2ee559e0cf008 or check the preprocessed sources. Check against another system etc. (there might be confliction versions installed, e.g. `/usr/include` vs `/usr/local/include`). – sehe Feb 02 '15 at 16:06

2 Answers2

9

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

sehe
  • 374,641
  • 47
  • 450
  • 633
  • I guess that my problem is having the old version from Ubuntu repositories. Anyway, I tried using lower(*it), boost::icl::lower(*it), and the upper siblings, but didn't worked. When using the boost::icl namespace, the error received is: "Invalid arguments. Candidates are boost::enable_if,boost::icl::domain_type_of<#0>::type>::type lower(const #0 &) boost::enable_if,boost::icl::interval_traits<#0>::domain_type>::type lower(const #0 &) – Roman Rdgz Jan 30 '15 at 07:47
  • BTW: I guess this makes no difference, but please consider that my interval_set is populated with boost::icl::discrete_interval::closed, in case it matters – Roman Rdgz Jan 30 '15 at 07:48
  • @RomanRdgz Looks like something else is slightly borked :/ If you can make it a SSCCE, I'll be happy to help (PS. Re. 2nd comment: that shouldn't matter, indeed) – sehe Jan 30 '15 at 07:48
  • I added the SSCCE. I mixed the code for lower and upper, just to check that any of them work for me. – Roman Rdgz Jan 30 '15 at 08:11
1

Finally, I realised that the errors where not from compilation but from Eclipse CDT, and have no effect at all.

Roman Rdgz
  • 12,836
  • 41
  • 131
  • 207
  • 1
    WOW. That's awesome. I'm happy I didn't encourage the wild goose chase! _(Lesson learned: consider feeding more context into the answer, if the question resists explanation without it)_. You should probably accept this as an answer (even though it doesn't relate to the question). It /might/ be helpful to a googler. – sehe Feb 04 '15 at 22:36
  • (Oh. I was suffering from buggy scaling in the new SO site design. Couldn't see the accept mark) – sehe Feb 04 '15 at 22:39
  • 1
    @sehe I have to thank you anyway. Even if you didn't solve my problem directly, you put a lot of effort helping me filtering the possible reasons. – Roman Rdgz Feb 05 '15 at 12:15