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

use*_*463 9 c++ boost boost-icl

我正在使用BOOST库中的interval_map.

typedef set<int> Tpopulations;    
interval_map<int, Tpopulations> populations;
Run Code Online (Sandbox Code Playgroud)

说我在人群中有这个

[1006311,1006353)   1611,1653,
[1006353,1006432)   1031,1611,1653,
[1006432,1006469]   1031,1387,1523,1611,1653,
(1006469,1006484]   1031,1387,1611,1653,
(1006484,1006496]   1031,1387,1611,
(1006496,1006506]   1031,1611,
(1006506,1006547]   1031,
Run Code Online (Sandbox Code Playgroud)

现在我想找出映射在某个数字上的内容:我希望如下:

cout << populations[1006313];  // 1611,1653
Run Code Online (Sandbox Code Playgroud)

要么

cout << populations.at(1006313);  // 1611,1653
Run Code Online (Sandbox Code Playgroud)

但是我似乎没有找到任何这样的方法.

我是否真的需要将其他间隔图定义为"窗口"并进行交叉?就像是:

interval_map<int, Tpopulations> window;
set<int>empty_set;
window +=(make_pair(1006313,empty_set));
cout << populations & window
Run Code Online (Sandbox Code Playgroud)

HEK*_*KTO 9

不,boost::icl::interval_map不包含这些元素访问函数.但是,您可以使用该find功能执行所需操作.

typedef std::set<int> Tpopulations;
typedef boost::icl::interval_map<int, Tpopulations> IMap;
typedef boost::icl::interval<int> Interval;
...
IMap m;
m += std::make_pair(Interval::right_open(1006311, 1006353), Tpopulations({1611, 1653}));
...
IMap::const_iterator it = m.find(1006313);
cout << it->first << endl;
...
Run Code Online (Sandbox Code Playgroud)

上面的代码将为您提供间隔,其中包含数字1006313.为了发送std::set<int>cout您,您需要额外的运算符:

inline std::ostream& operator<< (std::ostream& S, const Tpopulations& X)
{
  S << '(';
  for (ISet::const_iterator it = X.cbegin(); it != X.cend(); ++it)
  {
    if (it != X.cbegin()) S << ',';
    S << *it;
  }
  S << ')';
  return S;
}
Run Code Online (Sandbox Code Playgroud)

然后下面的行将打印您想要的内容:

cout << it->second << endl;
Run Code Online (Sandbox Code Playgroud)