123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- #ifndef BOOST_HISTOGRAM_MAKE_HISTOGRAM_HPP
- #define BOOST_HISTOGRAM_MAKE_HISTOGRAM_HPP
- #include <boost/histogram/accumulators/weighted_sum.hpp>
- #include <boost/histogram/detail/detect.hpp>
- #include <boost/histogram/histogram.hpp>
- #include <boost/histogram/storage_adaptor.hpp>
- #include <boost/histogram/unlimited_storage.hpp> // = default_storage
- #include <boost/mp11/utility.hpp>
- #include <tuple>
- #include <vector>
- namespace boost {
- namespace histogram {
- template <class Storage, class Axis, class... Axes,
- class = detail::requires_storage_or_adaptible<Storage>,
- class = detail::requires_axis<Axis>>
- auto make_histogram_with(Storage&& storage, Axis&& axis, Axes&&... axes) {
- auto a = std::make_tuple(std::forward<Axis>(axis), std::forward<Axes>(axes)...);
- using U = std::decay_t<Storage>;
- using S = mp11::mp_if<detail::is_storage<U>, U, storage_adaptor<U>>;
- return histogram<decltype(a), S>(std::move(a), S(std::forward<Storage>(storage)));
- }
- template <class Axis, class... Axes, class = detail::requires_axis<Axis>>
- auto make_histogram(Axis&& axis, Axes&&... axes) {
- return make_histogram_with(default_storage(), std::forward<Axis>(axis),
- std::forward<Axes>(axes)...);
- }
- template <class Axis, class... Axes, class = detail::requires_axis<Axis>>
- auto make_weighted_histogram(Axis&& axis, Axes&&... axes) {
- return make_histogram_with(weight_storage(), std::forward<Axis>(axis),
- std::forward<Axes>(axes)...);
- }
- template <class Storage, class Iterable,
- class = detail::requires_storage_or_adaptible<Storage>,
- class = detail::requires_sequence_of_any_axis<Iterable>>
- auto make_histogram_with(Storage&& storage, Iterable&& iterable) {
- using U = std::decay_t<Storage>;
- using S = mp11::mp_if<detail::is_storage<U>, U, storage_adaptor<U>>;
- using It = std::decay_t<Iterable>;
- using A = mp11::mp_if<detail::is_indexable_container<It>, It,
- std::vector<mp11::mp_first<It>>>;
- return histogram<A, S>(std::forward<Iterable>(iterable),
- S(std::forward<Storage>(storage)));
- }
- template <class Iterable, class = detail::requires_sequence_of_any_axis<Iterable>>
- auto make_histogram(Iterable&& iterable) {
- return make_histogram_with(default_storage(), std::forward<Iterable>(iterable));
- }
- template <class Iterable, class = detail::requires_sequence_of_any_axis<Iterable>>
- auto make_weighted_histogram(Iterable&& iterable) {
- return make_histogram_with(weight_storage(), std::forward<Iterable>(iterable));
- }
- template <class Storage, class Iterator,
- class = detail::requires_storage_or_adaptible<Storage>,
- class = detail::requires_iterator<Iterator>>
- auto make_histogram_with(Storage&& storage, Iterator begin, Iterator end) {
- using T = std::decay_t<decltype(*begin)>;
- return make_histogram_with(std::forward<Storage>(storage), std::vector<T>(begin, end));
- }
- template <class Iterator, class = detail::requires_iterator<Iterator>>
- auto make_histogram(Iterator begin, Iterator end) {
- return make_histogram_with(default_storage(), begin, end);
- }
- template <class Iterator, class = detail::requires_iterator<Iterator>>
- auto make_weighted_histogram(Iterator begin, Iterator end) {
- return make_histogram_with(weight_storage(), begin, end);
- }
- }
- }
- #endif
|