3

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?

HEKTO
  • 3,876
  • 2
  • 24
  • 45

1 Answers1

1

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).
Community
  • 1
  • 1
sehe
  • 374,641
  • 47
  • 450
  • 633
  • I think the page https://www.boost.org/doc/libs/1_67_0/libs/icl/doc/html/boost_icl/concepts/map_traits.html better describes what is going on with identity elements. You could update your answer and I'll accept it – HEKTO Jun 13 '18 at 18:53
  • @HEKTO you're quite right. I remembered reading it and couldn't find that page. It's much better indeed. – sehe Jun 13 '18 at 19:06