是什么让 Boost `interval_map` 忽略插入?

What makes the Boost `interval_map` to ignore insertion?

下面的代码应该将关联值为 0 和 1 的两个区间插入到 Boost 区间图中,但它只插入了一个:

#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;
}

输出:

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

如果我将 "ignored" 行的值更改为 1,它将正确插入该对。

这是为什么?

任何“无值”的域间隔在共同域中都有一个隐含的“0”。反之亦然。我想下面的示例会立即有意义:

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

生成一张空地图。

参见Map Traits

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

具体在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).