Linked Questions

Popular Questions

Boost ICL map that replaces values in intervals?

Asked by At

Boost.ICL's interval_map has two kinds of behaviors: += and insert. Both are useful in different context. The first adds up values in common intersections of two existing intervals. The second simply introduces the new value only in previously unassigned intervals (in previously assigned intervals the value is kept).

However I need a behavior that is subtly different, such that, in the example below instead of getting the undesired interval map (1.,2.)->1 , (2.5,3.)->3, (3.,5.)->2 I get instead the desired (1.,2.)->1 , (2.5,5.)->3.

That is, that new inserted values replace old values? How do I declare interval_map to get that replacing behavior?

int main(){
    boost::icl::interval_map<double, int> joined_map;
    joined_map.insert( std::make_pair(
        boost::icl::interval<double>::open(1., 2.),
    joined_map.insert( std::make_pair(
        boost::icl::interval<double>::open(3., 5.),
    joined_map.insert( std::make_pair(
        boost::icl::interval<double>::open(2.5, 5.),
    )); // this line doesn't replace the old value 2, it keeps it.

Bonus: Is that what boost::icl::map is supposed to do? How do I use it?

Related Questions