histogram/examples/guide_custom_minimal_axis.cpp
2019-01-11 00:06:26 +01:00

30 lines
675 B
C++

// Copyright 2015-2018 Hans Dembinski
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt
// or copy at http://www.boost.org/LICENSE_1_0.txt)
//[ guide_custom_minimal_axis
#include <boost/histogram.hpp>
#include <cassert>
namespace bh = boost::histogram;
// stateless axis which returns 1 if the input is even and 0 otherwise
struct minimal_axis {
int operator()(int x) const { return x % 2; }
unsigned size() const { return 2; }
};
int main() {
auto h = bh::make_histogram(minimal_axis());
h(0); h(1); h(2);
assert(h.at(0) == 2); // two even numbers
assert(h.at(1) == 1); // one uneven number
}
//]