diff --git a/include/boost/histogram/histogram.hpp b/include/boost/histogram/histogram.hpp index 0fb327ae..5de875f8 100644 --- a/include/boost/histogram/histogram.hpp +++ b/include/boost/histogram/histogram.hpp @@ -266,14 +266,6 @@ private: void serialize(Archive&, unsigned); }; -/// static type factory -template -histogram...>> make_static_histogram(Ts&&... axis) { - using histogram_type = histogram...>>; - auto axes = typename histogram_type::axes_type(std::forward(axis)...); - return histogram_type(std::move(axes)); -} - /// static type factory with custom storage type template histogram...>, detail::rm_cv_ref> @@ -284,75 +276,53 @@ make_static_histogram_with(Storage&& s, Ts&&... axis) { return histogram_type(std::move(axes), std::move(s)); } -/// dynamic type factory -template -histogram, detail::rm_cv_ref...>, - dynamic_axes>> -make_dynamic_histogram(T&& axis0, Ts&&... axis) { - using histogram_type = histogram< - mp11::mp_rename, - detail::rm_cv_ref...>, - dynamic_axes>>; - using value_type = typename histogram_type::axes_type::value_type; - auto axes = typename histogram_type::axes_type( - {value_type(std::forward(axis0)), value_type(std::forward(axis))...}); - return histogram_type(std::move(axes)); +/// static type factory with standard storage type +template +histogram...>> make_static_histogram(Ts&&... axis) { + using S = typename histogram...>>::storage_type; + return make_static_histogram_with(S(), std::forward(axis)...); } /// dynamic type factory with custom storage type -template -histogram, - detail::rm_cv_ref...>, - dynamic_axes>, - detail::rm_cv_ref> +template +histogram, detail::rm_cv_ref> make_dynamic_histogram_with(Storage&& s, T&& axis0, Ts&&... axis) { using histogram_type = histogram< - mp11::mp_rename, - detail::rm_cv_ref...>, - dynamic_axes>, - detail::rm_cv_ref>; - using axis_type = typename histogram_type::axes_type::value_type; + mp11::mp_rename, detail::rm_cv_ref + >; auto a = axis0.get_allocator(); auto axes = typename histogram_type::axes_type( - {axis_type(std::forward(axis0)), axis_type(std::forward(axis))...}, a); + {AnyAxisType(std::forward(axis0)), AnyAxisType(std::forward(axis))...}, a); return histogram_type(std::move(axes), std::move(s)); } -/// dynamic type factory from axis iterators -template > -histogram, - dynamic_axes>> -make_dynamic_histogram(Iterator begin, Iterator end) { - BOOST_ASSERT_MSG(std::distance(begin, end) > 0, "at least one axis required"); - using histogram_type = histogram, - dynamic_axes>>; - // auto axes = typename histogram_type::axes_type(begin, end, begin->get_allocator()); - auto axes = typename histogram_type::axes_type(begin, end); - return histogram_type(std::move(axes)); +/// dynamic type factory with standard storage type +template +histogram> +make_dynamic_histogram(T&& axis0, Ts&&... axis) { + using S = typename histogram>::storage_type; + return make_dynamic_histogram_with(S(), std::forward(axis0), std::forward(axis)...); } /// dynamic type factory from axis iterators with custom storage type template > -histogram, - dynamic_axes>, - Storage> +histogram> make_dynamic_histogram_with(Storage&& s, Iterator begin, Iterator end) { BOOST_ASSERT_MSG(std::distance(begin, end) > 0, "at least one axis required"); - using histogram_type = - histogram, - dynamic_axes>, - Storage>; - // auto axes = typename histogram_type::axes_type(begin, end, begin->get_allocator()); - auto axes = typename histogram_type::axes_type(begin, end); + using histogram_type = histogram>; + auto axes = typename histogram_type::axes_type(begin, end, begin->get_allocator()); return histogram_type(std::move(axes), std::move(s)); } +/// dynamic type factory from axis iterators with standard storage type +template > +histogram +make_dynamic_histogram(Iterator begin, Iterator end) { + using S = typename histogram::storage_type; + return make_dynamic_histogram_with(S(), begin, end); +} + } // namespace histogram } // namespace boost diff --git a/include/boost/histogram/histogram_fwd.hpp b/include/boost/histogram/histogram_fwd.hpp index 8362be4c..97aa4c69 100644 --- a/include/boost/histogram/histogram_fwd.hpp +++ b/include/boost/histogram/histogram_fwd.hpp @@ -55,14 +55,14 @@ class adaptive_storage; template > class array_storage; -namespace { +namespace detail { template -using rebind = typename std::allocator_traits>::allocator_type>::template rebind_alloc>; +using rebind_allocator = typename std::allocator_traits>::allocator_type>::template rebind_alloc>; } template -using dynamic_axes = std::vector, rebind>; +using dynamic_axes = std::vector, detail::rebind_allocator>; template using static_axes = std::tuple; diff --git a/test/utility.hpp b/test/utility.hpp index 03a3ff99..8825adb2 100644 --- a/test/utility.hpp +++ b/test/utility.hpp @@ -64,22 +64,22 @@ auto make(static_tag, Axes&&... axes) return make_static_histogram(std::forward(axes)...); } -template -auto make(dynamic_tag, Axes&&... axes) - -> decltype(make_dynamic_histogram(std::forward(axes)...)) { - return make_dynamic_histogram(std::forward(axes)...); -} - template auto make_s(static_tag, S&& s, Axes&&... axes) -> decltype(make_static_histogram_with(s, std::forward(axes)...)) { return make_static_histogram_with(s, std::forward(axes)...); } +template +auto make(dynamic_tag, Axes&&... axes) + -> decltype(make_dynamic_histogram...>>(std::forward(axes)...)) { + return make_dynamic_histogram...>>(std::forward(axes)...); +} + template auto make_s(dynamic_tag, S&& s, Axes&&... axes) - -> decltype(make_dynamic_histogram_with(s, std::forward(axes)...)) { - return make_dynamic_histogram_with(s, std::forward(axes)...); + -> decltype(make_dynamic_histogram_with...>>(s, std::forward(axes)...)) { + return make_dynamic_histogram_with...>>(s, std::forward(axes)...); } template