]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/histogram/examples/guide_custom_minimal_axis.cpp
1 // Copyright 2015-2018 Hans Dembinski
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)
7 //[ guide_custom_minimal_axis
9 #include <boost/histogram.hpp>
13 using namespace boost::histogram
;
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; }
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; }
29 auto h
= make_histogram(even_odd_axis(), threshold_axis(3.0));
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