fixing compilation of histogram_test, removed redundant code in make_*_histogram variants, more control over types allowed by make_dynamic_histogram*

This commit is contained in:
Hans Dembinski
2018-08-21 12:37:17 +02:00
parent affe12e4cd
commit 8216af927e
3 changed files with 39 additions and 69 deletions

View File

@@ -266,14 +266,6 @@ private:
void serialize(Archive&, unsigned);
};
/// static type factory
template <typename... Ts>
histogram<static_axes<detail::rm_cv_ref<Ts>...>> make_static_histogram(Ts&&... axis) {
using histogram_type = histogram<static_axes<detail::rm_cv_ref<Ts>...>>;
auto axes = typename histogram_type::axes_type(std::forward<Ts>(axis)...);
return histogram_type(std::move(axes));
}
/// static type factory with custom storage type
template <typename Storage, typename... Ts>
histogram<static_axes<detail::rm_cv_ref<Ts>...>, detail::rm_cv_ref<Storage>>
@@ -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 <typename T, typename... Ts>
histogram<mp11::mp_rename<
mp11::mp_set_push_back<axis::any_std, detail::rm_cv_ref<T>, detail::rm_cv_ref<Ts>...>,
dynamic_axes>>
make_dynamic_histogram(T&& axis0, Ts&&... axis) {
using histogram_type = histogram<
mp11::mp_rename<mp11::mp_set_push_back<axis::any_std, detail::rm_cv_ref<T>,
detail::rm_cv_ref<Ts>...>,
dynamic_axes>>;
using value_type = typename histogram_type::axes_type::value_type;
auto axes = typename histogram_type::axes_type(
{value_type(std::forward<T>(axis0)), value_type(std::forward<Ts>(axis))...});
return histogram_type(std::move(axes));
/// static type factory with standard storage type
template <typename... Ts>
histogram<static_axes<detail::rm_cv_ref<Ts>...>> make_static_histogram(Ts&&... axis) {
using S = typename histogram<static_axes<detail::rm_cv_ref<Ts>...>>::storage_type;
return make_static_histogram_with(S(), std::forward<Ts>(axis)...);
}
/// dynamic type factory with custom storage type
template <typename Storage, typename T, typename... Ts>
histogram<mp11::mp_rename<mp11::mp_set_push_back<axis::any_std, detail::rm_cv_ref<T>,
detail::rm_cv_ref<Ts>...>,
dynamic_axes>,
detail::rm_cv_ref<Storage>>
template <typename AnyAxisType=axis::any_std, typename Storage, typename T, typename... Ts>
histogram<mp11::mp_rename<AnyAxisType, dynamic_axes>, detail::rm_cv_ref<Storage>>
make_dynamic_histogram_with(Storage&& s, T&& axis0, Ts&&... axis) {
using histogram_type = histogram<
mp11::mp_rename<mp11::mp_set_push_back<axis::any_std, detail::rm_cv_ref<T>,
detail::rm_cv_ref<Ts>...>,
dynamic_axes>,
detail::rm_cv_ref<Storage>>;
using axis_type = typename histogram_type::axes_type::value_type;
mp11::mp_rename<AnyAxisType, dynamic_axes>, detail::rm_cv_ref<Storage>
>;
auto a = axis0.get_allocator();
auto axes = typename histogram_type::axes_type(
{axis_type(std::forward<T>(axis0)), axis_type(std::forward<Ts>(axis))...}, a);
{AnyAxisType(std::forward<T>(axis0)), AnyAxisType(std::forward<Ts>(axis))...}, a);
return histogram_type(std::move(axes), std::move(s));
}
/// dynamic type factory from axis iterators
template <typename Iterator, typename = detail::requires_iterator<Iterator>>
histogram<mp11::mp_rename<
detail::mp_set_union<axis::any_std, typename Iterator::value_type::types>,
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<mp11::mp_rename<
detail::mp_set_union<axis::any_std, typename Iterator::value_type::types>,
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 <typename AnyAxisType=axis::any_std, typename T, typename... Ts>
histogram<mp11::mp_rename<AnyAxisType, dynamic_axes>>
make_dynamic_histogram(T&& axis0, Ts&&... axis) {
using S = typename histogram<mp11::mp_rename<AnyAxisType, dynamic_axes>>::storage_type;
return make_dynamic_histogram_with<AnyAxisType>(S(), std::forward<T>(axis0), std::forward<Ts>(axis)...);
}
/// dynamic type factory from axis iterators with custom storage type
template <typename Storage, typename Iterator,
typename = detail::requires_iterator<Iterator>>
histogram<mp11::mp_rename<
detail::mp_set_union<axis::any_std, typename Iterator::value_type::types>,
dynamic_axes>,
Storage>
histogram<typename Iterator::value_type, detail::rm_cv_ref<Storage>>
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<mp11::mp_rename<detail::mp_set_union<
axis::any_std, typename Iterator::value_type::types>,
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<typename Iterator::value_type, detail::rm_cv_ref<Storage>>;
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 <typename Iterator, typename = detail::requires_iterator<Iterator>>
histogram<typename Iterator::value_type>
make_dynamic_histogram(Iterator begin, Iterator end) {
using S = typename histogram<typename Iterator::value_type>::storage_type;
return make_dynamic_histogram_with(S(), begin, end);
}
} // namespace histogram
} // namespace boost

View File

@@ -55,14 +55,14 @@ class adaptive_storage;
template <typename T, typename Allocator = std::allocator<T>>
class array_storage;
namespace {
namespace detail {
template <typename... Ts>
using rebind = typename std::allocator_traits<typename mp11::mp_front<
mp11::mp_list<Ts...>>::allocator_type>::template rebind_alloc<axis::any<Ts...>>;
using rebind_allocator = typename std::allocator_traits<typename mp11::mp_front<
mp11::mp_list<Ts...>>::allocator_type>::template rebind_alloc<axis::any<Ts...>>;
}
template <typename... Ts>
using dynamic_axes = std::vector<axis::any<Ts...>, rebind<Ts...>>;
using dynamic_axes = std::vector<axis::any<Ts...>, detail::rebind_allocator<Ts...>>;
template <typename... Ts>
using static_axes = std::tuple<Ts...>;

View File

@@ -64,22 +64,22 @@ auto make(static_tag, Axes&&... axes)
return make_static_histogram(std::forward<Axes>(axes)...);
}
template <typename... Axes>
auto make(dynamic_tag, Axes&&... axes)
-> decltype(make_dynamic_histogram(std::forward<Axes>(axes)...)) {
return make_dynamic_histogram(std::forward<Axes>(axes)...);
}
template <typename S, typename... Axes>
auto make_s(static_tag, S&& s, Axes&&... axes)
-> decltype(make_static_histogram_with(s, std::forward<Axes>(axes)...)) {
return make_static_histogram_with(s, std::forward<Axes>(axes)...);
}
template <typename... Axes>
auto make(dynamic_tag, Axes&&... axes)
-> decltype(make_dynamic_histogram<axis::any<detail::rm_cv_ref<Axes>...>>(std::forward<Axes>(axes)...)) {
return make_dynamic_histogram<axis::any<detail::rm_cv_ref<Axes>...>>(std::forward<Axes>(axes)...);
}
template <typename S, typename... Axes>
auto make_s(dynamic_tag, S&& s, Axes&&... axes)
-> decltype(make_dynamic_histogram_with(s, std::forward<Axes>(axes)...)) {
return make_dynamic_histogram_with(s, std::forward<Axes>(axes)...);
-> decltype(make_dynamic_histogram_with<axis::any<detail::rm_cv_ref<Axes>...>>(s, std::forward<Axes>(axes)...)) {
return make_dynamic_histogram_with<axis::any<detail::rm_cv_ref<Axes>...>>(s, std::forward<Axes>(axes)...);
}
template <class T>