简体   繁体   English

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

[英]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: 下面的代码应该在Boost间隔图中插入两个关联值分别为0和1的间隔,但是只插入一个:

#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. 如果我将“ ignored”行的值更改为1,它将正确插入该对。

Why is that? 这是为什么?

Any domain interval with "no value" has an implicit "0" in the co-domain. 具有“无值”的任何域间隔在共同域中都具有隐式“ 0”。 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. Icl映射的行为不同,这取决于它们如何处理关联类型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. icl图可以是身份吸收者或身份丰富者。

  • A identity absorber never stores value pairs (k,0) that carry identity elements. 身份吸收器从不存储携带身份元素的值对(k,0)。
  • A identity enricher stores value pairs (k,0). 身份丰富器存储值对(k,0)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM