2012/6/18 Rajalakshmi Iyer <raj@blismedia.com>
Hello,

I want to know if I can use the boost::icl::interval_set to store a set of integer based intervals like:
[100, 200], [50, 600] etc

and then find out whether a number like 150 matches any of these intervals?

An icl::interval_set does not store the individual intervals that are inserted into it, if they overlap. Basically the interval set is just a set that stores contiguous chunks of elements in a compact way as intervals. So ...

#include <boost/icl/interval_set.hpp>
#include <boost/icl/interval.hpp>
using namespace std;
using namespace boost::icl;

interval_set<int> aSet;                 //aSet={}
aSet += interval<int>::closed(100,200); //aSet={[100,200]}
aSet += interval<int>::closed( 50,600); //aSet={[ 50,600]}
cout << "aSet " << 
    (contains(aSet, 150) ? "contains 150\n" 
                         : "does not contain 150\n");

The example you ask for will look like this.

HTH,
Joachim

  
--
Interval Container Library [Boost.Icl]
http://www.joachim-faulhaber.de