• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2015-2018 Hans Dembinski
2 //
3 // Distributed under the Boost Software License, Version 1.0.
4 // (See accompanying file LICENSE_1_0.txt
5 // or copy at http://www.boost.org/LICENSE_1_0.txt)
6 
7 //[ guide_custom_minimal_axis
8 
9 #include <boost/histogram.hpp>
10 #include <cassert>
11 
main()12 int main() {
13   using namespace boost::histogram;
14 
15   // stateless axis which returns 1 if the input is even and 0 otherwise
16   struct even_odd_axis {
17     axis::index_type index(int x) const { return x % 2; }
18     axis::index_type size() const { return 2; }
19   };
20 
21   // threshold axis which returns 1 if the input is above threshold
22   struct threshold_axis {
23     threshold_axis(double x) : thr(x) {}
24     axis::index_type index(double x) const { return x >= thr; }
25     axis::index_type size() const { return 2; }
26     double thr;
27   };
28 
29   auto h = make_histogram(even_odd_axis(), threshold_axis(3.0));
30 
31   h(0, 2.0);
32   h(1, 4.0);
33   h(2, 4.0);
34 
35   assert(h.at(0, 0) == 1); // even, below threshold
36   assert(h.at(0, 1) == 1); // even, above threshold
37   assert(h.at(1, 0) == 0); // odd, below threshold
38   assert(h.at(1, 1) == 1); // odd, above threshold
39 }
40 
41 //]
42