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

标签 c++ boost-icl

下面的代码应该将关联值为 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/

相关文章:

java - 如何通过 JNA 从多个线程安全地调用 C++ 函数?

c++ - 为什么 std::set 没有 "contains"成员函数?

c++ - 我终于在链表中创建了我的添加函数,但不能在 main 中使用。 :(

c++ - 我可以用 Boost interval_map 做到这一点吗?

c++ - Boost ICL : Are some combinations of interval types and functions not implemented?中函数 "contains"的基本使用

c++ - N Boost interval_set 的组合

c++ - Qt:从固定数量的字节到整数

c++ - 在为请求选择服务的情况下,使用 Boost ICL 而不是 for_each 是否可能且合理?

c++ - boost interval_map 是否有 operator [] 或 .at() 方法?

c++ - 在 PropertyPage 上的控件上显示工具提示。将 TRUE 返回到 ON_NOTIFY_EX(TTN_NEEDTEXT...) 时崩溃