]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/histogram/make_histogram.hpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / boost / histogram / make_histogram.hpp
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 #ifndef BOOST_HISTOGRAM_MAKE_HISTOGRAM_HPP
8 #define BOOST_HISTOGRAM_MAKE_HISTOGRAM_HPP
9
10 /**
11 \file boost/histogram/make_histogram.hpp
12 Collection of factory functions to conveniently create histograms.
13 */
14
15 #include <boost/histogram/accumulators/weighted_sum.hpp>
16 #include <boost/histogram/histogram.hpp>
17 #include <boost/histogram/storage_adaptor.hpp>
18 #include <boost/histogram/unlimited_storage.hpp> // = default_storage
19 #include <boost/mp11/utility.hpp>
20 #include <tuple>
21 #include <vector>
22
23 namespace boost {
24 namespace histogram {
25
26 /**
27 Make histogram from compile-time axis configuration and custom storage.
28 @param storage Storage or container with standard interface (any vector, array, or map).
29 @param axis First axis instance.
30 @param axes Other axis instances.
31 */
32 template <class Storage, class Axis, class... Axes,
33 class = detail::requires_storage_or_adaptible<Storage>,
34 class = detail::requires_axis<Axis>>
35 auto make_histogram_with(Storage&& storage, Axis&& axis, Axes&&... axes) {
36 auto a = std::make_tuple(std::forward<Axis>(axis), std::forward<Axes>(axes)...);
37 using U = std::decay_t<Storage>;
38 using S = mp11::mp_if<detail::is_storage<U>, U, storage_adaptor<U>>;
39 return histogram<decltype(a), S>(std::move(a), S(std::forward<Storage>(storage)));
40 }
41
42 /**
43 Make histogram from compile-time axis configuration and default storage.
44 @param axis First axis instance.
45 @param axes Other axis instances.
46 */
47 template <class Axis, class... Axes, class = detail::requires_axis<Axis>>
48 auto make_histogram(Axis&& axis, Axes&&... axes) {
49 return make_histogram_with(default_storage(), std::forward<Axis>(axis),
50 std::forward<Axes>(axes)...);
51 }
52
53 /**
54 Make histogram from compile-time axis configuration and weight-counting storage.
55 @param axis First axis instance.
56 @param axes Other axis instances.
57 */
58 template <class Axis, class... Axes, class = detail::requires_axis<Axis>>
59 auto make_weighted_histogram(Axis&& axis, Axes&&... axes) {
60 return make_histogram_with(weight_storage(), std::forward<Axis>(axis),
61 std::forward<Axes>(axes)...);
62 }
63
64 /**
65 Make histogram from iterable range and custom storage.
66 @param storage Storage or container with standard interface (any vector, array, or map).
67 @param iterable Iterable range of axis objects.
68 */
69 template <class Storage, class Iterable,
70 class = detail::requires_storage_or_adaptible<Storage>,
71 class = detail::requires_sequence_of_any_axis<Iterable>>
72 auto make_histogram_with(Storage&& storage, Iterable&& iterable) {
73 using U = std::decay_t<Storage>;
74 using S = mp11::mp_if<detail::is_storage<U>, U, storage_adaptor<U>>;
75 using It = std::decay_t<Iterable>;
76 using A = mp11::mp_if<detail::is_indexable_container<It>, It,
77 std::vector<mp11::mp_first<It>>>;
78 return histogram<A, S>(std::forward<Iterable>(iterable),
79 S(std::forward<Storage>(storage)));
80 }
81
82 /**
83 Make histogram from iterable range and default storage.
84 @param iterable Iterable range of axis objects.
85 */
86 template <class Iterable, class = detail::requires_sequence_of_any_axis<Iterable>>
87 auto make_histogram(Iterable&& iterable) {
88 return make_histogram_with(default_storage(), std::forward<Iterable>(iterable));
89 }
90
91 /**
92 Make histogram from iterable range and weight-counting storage.
93 @param iterable Iterable range of axis objects.
94 */
95 template <class Iterable, class = detail::requires_sequence_of_any_axis<Iterable>>
96 auto make_weighted_histogram(Iterable&& iterable) {
97 return make_histogram_with(weight_storage(), std::forward<Iterable>(iterable));
98 }
99
100 /**
101 Make histogram from iterator interval and custom storage.
102 @param storage Storage or container with standard interface (any vector, array, or map).
103 @param begin Iterator to range of axis objects.
104 @param end Iterator to range of axis objects.
105 */
106 template <class Storage, class Iterator,
107 class = detail::requires_storage_or_adaptible<Storage>,
108 class = detail::requires_iterator<Iterator>>
109 auto make_histogram_with(Storage&& storage, Iterator begin, Iterator end) {
110 using T = std::decay_t<decltype(*begin)>;
111 return make_histogram_with(std::forward<Storage>(storage), std::vector<T>(begin, end));
112 }
113
114 /**
115 Make histogram from iterator interval and default storage.
116 @param begin Iterator to range of axis objects.
117 @param end Iterator to range of axis objects.
118 */
119 template <class Iterator, class = detail::requires_iterator<Iterator>>
120 auto make_histogram(Iterator begin, Iterator end) {
121 return make_histogram_with(default_storage(), begin, end);
122 }
123
124 /**
125 Make histogram from iterator interval and weight-counting storage.
126 @param begin Iterator to range of axis objects.
127 @param end Iterator to range of axis objects.
128 */
129 template <class Iterator, class = detail::requires_iterator<Iterator>>
130 auto make_weighted_histogram(Iterator begin, Iterator end) {
131 return make_histogram_with(weight_storage(), begin, end);
132 }
133
134 } // namespace histogram
135 } // namespace boost
136
137 #endif