MCPcopy Create free account
hub / github.com/boostorg/histogram / main

Function main

examples/guide_fill_histogram.cpp:9–35  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7namespace bh = boost::histogram;
8
9int main() {
10 auto h = bh::make_static_histogram(bh::axis::regular<>(8, 0, 4),
11 bh::axis::regular<>(10, 0, 5));
12
13 // fill histogram, number of arguments must be equal to number of axes
14 h(0, 1.1); // increases bin counter by one
15 h(bh::weight(2), 3, 3.4); // increase bin counter by 2 instead of 1
16
17 // histogram also supports fills from a container of values; a container
18 // of wrong size trips an assertion in debug mode
19 auto xy1 = std::make_pair(4, 3.1);
20 h(xy1);
21 auto xy2 = std::vector<double>({3.0, 4.9});
22 h(xy2);
23
24 // functional-style processing is also supported
25 std::vector<std::pair<int, double>> input_data{
26 {0, 1.2}, {2, 3.4}, {4, 5.6}};
27 // std::for_each takes the functor by value, thus it potentially makes
28 // expensive copies of the histogram, but modern compilers are usually smart
29 // enough to avoid the superfluous copies
30 auto h2 =
31 std::for_each(input_data.begin(), input_data.end(),
32 bh::make_static_histogram(bh::axis::regular<>(8, 0, 4),
33 bh::axis::regular<>(10, 0, 5)));
34 // h2 is filled
35}
36
37//]

Callers

nothing calls this directly

Calls 4

make_static_histogramFunction · 0.85
weightFunction · 0.85
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected