]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/histogram/examples/guide_custom_modified_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_modified_axis
9 #include <boost/histogram.hpp>
15 using namespace boost::histogram
;
17 // custom axis, which adapts builtin integer axis
18 struct custom_axis
: public axis::integer
<> {
19 using value_type
= const char*; // type that is fed to the axis
21 using integer::integer
; // inherit ctors of base
23 // the customization point
24 // - accept const char* and convert to int
25 // - then call index method of base class
26 axis::index_type
index(value_type s
) const { return integer::index(std::atoi(s
)); }
29 auto h
= make_histogram(custom_axis(3, 6));
35 std::ostringstream os
;
36 for (auto&& b
: indexed(h
)) {
37 os
<< "bin " << b
.index() << " [" << b
.bin() << "] " << *b
<< "\n";
40 std::cout
<< os
.str() << std::endl
;
42 assert(os
.str() == "bin 0 [3] 1\n"