X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=ceph%2Fsrc%2Fboost%2Flibs%2Fhistogram%2Fexamples%2Fguide_custom_accumulators_with_metadata.cpp;fp=ceph%2Fsrc%2Fboost%2Flibs%2Fhistogram%2Fexamples%2Fguide_custom_accumulators_with_metadata.cpp;h=478f97842c3673883d66a1c7bd0363241179b5dc;hb=f67539c23b11f3b8a2ecaeeddf7a403ae1c442a8;hp=0000000000000000000000000000000000000000;hpb=64a4c04e6850c6d9086e4c37f57c4eada541b05e;p=ceph.git diff --git a/ceph/src/boost/libs/histogram/examples/guide_custom_accumulators_with_metadata.cpp b/ceph/src/boost/libs/histogram/examples/guide_custom_accumulators_with_metadata.cpp new file mode 100644 index 000000000..478f97842 --- /dev/null +++ b/ceph/src/boost/libs/histogram/examples/guide_custom_accumulators_with_metadata.cpp @@ -0,0 +1,47 @@ +// Copyright 2019 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_accumulators_with_metadata + +#include +#include +#include +#include +#include + +int main() { + using namespace boost::histogram; + + // derive custom accumulator from one of the builtins + struct accumulator_with_metadata : accumulators::count<> { + std::string meta; // custom meta data + + // arbitrary additional data and interface could be added here + }; + + // make 1D histogram with custom accmulator + auto h = make_histogram_with(dense_storage(), + axis::integer<>(1, 4)); + + // fill some weighted entries + auto x = {1, 0, 2, 1}; + h.fill(x); + + // assigning meta data to two bins + h[0].meta = "Foo"; + h[2].meta = "Bar"; + + std::ostringstream os; + for (auto&& x : indexed(h)) + os << x.bin() << " value " << x->value() << " meta " << x->meta << "\n"; + + std::cout << os.str() << std::flush; + assert(os.str() == "1 value 2 meta Foo\n" + "2 value 1 meta \n" + "3 value 0 meta Bar\n"); +} + +//]