【发布时间】:2019-08-01 15:20:05
【问题描述】:
我正在尝试新的 boost::histogram 库,但在一些基本用法上遇到了问题。将新数据点添加到直方图时,我想知道分配给它的 bin 的索引。插入的方法返回 void 所以我试图使用 STL 算法来定位 bin 但编译器抱怨。这是代码,从文档中的一个示例修改
#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>
#include <string>
#include <boost/format.hpp> // only needed for printing
#include <boost/histogram.hpp> // make_histogram, regular, weight, indexed
namespace bh = boost::histogram;
using namespace std;
int main() {
vector<double> v = {1.0, 2.0, 3.0, 4.0, 5.0};
auto h = bh::make_static_histogram(bh::axis::variable<>(v.begin(), v.end()));
vector<double> data = {-0.5, 1.1, 2.3, 3.7, 3.0, 2.999};
std::for_each(data.begin(), data.end(), std::ref(h));
auto it = lower_bound(h.begin(), h.end(), 3.0);
cout << it.idx(0) << endl;
return 0;
}
编译器会吐出一堆错误,但我认为归结为lower_bound 无法进行对象比较的事实。库文档似乎暗示支持 STL 算法。 感谢您的帮助
【问题讨论】: