]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/histogram/examples/guide_custom_modified_axis.cpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / libs / histogram / examples / guide_custom_modified_axis.cpp
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_modified_axis
8
9 #include <boost/histogram.hpp>
10 #include <cassert>
11 #include <iostream>
12 #include <sstream>
13
14 int main() {
15 using namespace boost::histogram;
16
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
20
21 using integer::integer; // inherit ctors of base
22
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)); }
27 };
28
29 auto h = make_histogram(custom_axis(3, 6));
30 h("-10");
31 h("3");
32 h("4");
33 h("9");
34
35 std::ostringstream os;
36 for (auto&& b : indexed(h)) {
37 os << "bin " << b.index() << " [" << b.bin() << "] " << *b << "\n";
38 }
39
40 std::cout << os.str() << std::endl;
41
42 assert(os.str() == "bin 0 [3] 1\n"
43 "bin 1 [4] 1\n"
44 "bin 2 [5] 0\n");
45 }
46
47 //]