Boost logo

Boost Users :

Subject: Re: [Boost-users] Using Boost ICL for range matching
From: Joachim Faulhaber (afojgo_at_[hidden])
Date: 2012-06-21 03:17:28


2012/6/18 Rajalakshmi Iyer <raj_at_[hidden]>

> 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


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net