下面的代码应该将关联值为 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)}
如果我将“忽略”行的值更改为 1,它将正确插入该对。
这是为什么?
最佳答案
任何“无值”的域间隔在共同域中都有一个隐含的“0”。反之亦然。我想下面的示例会立即有意义:
m += std::make_pair(Interval::right_open(8,15), 1);
m -= std::make_pair(Interval::right_open(8,15), 1);
生成一个空 map 。
参见 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).
关于c++ - 是什么让 Boost `interval_map` 忽略插入?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50822545/