auto xy = std::make_tuple(1, 0.3);
h(xy);
- // functional-style processing is also supported, generate some data...
- std::vector<std::tuple<int, double>> input_data;
- input_data.emplace_back(0, 0.8);
- input_data.emplace_back(2, 0.4);
- input_data.emplace_back(5, 0.7); // goes into overflow bin of first axis
+ // chunk-wise filling is also supported and more efficient, make some data...
+ std::vector<double> xy2[2] = {{0, 2, 5}, {0.8, 0.4, 0.7}};
- // std::for_each takes the functor by value, a reference wrapper avoid copies
- std::for_each(input_data.begin(), input_data.end(), std::ref(h));
+ // ... and call fill method
+ h.fill(xy2);
- // once histogram is filled, access cells using operator[] or at(...)
+ // once histogram is filled, access individual cells using operator[] or at(...)
// - operator[] can only accept a single argument in the current version of C++,
// it is convenient when you have a 1D histogram
// - at(...) can accept several values, so use this by default
// iteration over values works, but see next example for a better way
// - iteration using begin() and end() includes under- and overflow bins
- // - iteration order is an implementation detail and may change in future versions
+ // - iteration order is an implementation detail and should not be relied upon
const double sum = std::accumulate(h.begin(), h.end(), 0.0);
assert(sum == 6);
}