简体   繁体   中英

What makes the Boost `interval_map` to ignore insertion?

The code below is supposed to insert two intervals with associated values 0 and 1 into the Boost interval map, but it inserts only one:

#include <iostream>

#include <boost/icl/interval_map.hpp>

using Interval = boost::icl::interval<int>;
using IMap = boost::icl::interval_map<int, int>;

int main()
{
  IMap m;
  m += std::make_pair(Interval::right_open(0, 7), 0);  // <== ignored?
  m += std::make_pair(Interval::right_open(8,15), 1);
  std::cout << m << std::endl;
}

Output:

{([8,15)->1)}

If I change the value for the "ignored" line to 1, it will insert the pair correctly.

Why is that?

Any domain interval with "no value" has an implicit "0" in the co-domain. And vice versa. I guess the following sample would make sense immediately:

m += std::make_pair(Interval::right_open(8,15), 1);
m -= std::make_pair(Interval::right_open(8,15), 1);

Results in an empty map.

See Map Traits .

Icl maps differ in their behavior dependent on how they handle identity elements of the associated type CodomainT.

Specifically under Definedness and Storage of Identity Elements

The second trait is related to the representation of identity elements in the map. An icl map can be a identity absorber or a identity enricher.

  • A identity absorber never stores value pairs (k,0) that carry identity elements.
  • A identity enricher stores value pairs (k,0).

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