summaryrefslogtreecommitdiff
path: root/boost/histogram/algorithm/project.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'boost/histogram/algorithm/project.hpp')
-rw-r--r--boost/histogram/algorithm/project.hpp28
1 files changed, 16 insertions, 12 deletions
diff --git a/boost/histogram/algorithm/project.hpp b/boost/histogram/algorithm/project.hpp
index be69fe87b6..6c0495c8d0 100644
--- a/boost/histogram/algorithm/project.hpp
+++ b/boost/histogram/algorithm/project.hpp
@@ -8,16 +8,20 @@
#define BOOST_HISTOGRAM_ALGORITHM_PROJECT_HPP
#include <algorithm>
-#include <boost/histogram/detail/meta.hpp>
+#include <boost/histogram/axis/variant.hpp>
+#include <boost/histogram/detail/detect.hpp>
+#include <boost/histogram/detail/make_default.hpp>
+#include <boost/histogram/detail/static_if.hpp>
#include <boost/histogram/histogram.hpp>
#include <boost/histogram/indexed.hpp>
#include <boost/histogram/unsafe_access.hpp>
-#include <boost/mp11/algorithm.hpp>
#include <boost/mp11/list.hpp>
#include <boost/mp11/set.hpp>
+#include <boost/mp11/utility.hpp>
#include <boost/throw_exception.hpp>
#include <stdexcept>
#include <type_traits>
+#include <vector>
namespace boost {
namespace histogram {
@@ -41,8 +45,7 @@ auto project(const histogram<A, S>& h, std::integral_constant<unsigned, N>, Ns..
return std::make_tuple(std::get<N>(old_axes), std::get<Ns::value>(old_axes)...);
},
[&](const auto& old_axes) {
- return detail::remove_cvref_t<decltype(old_axes)>(
- {old_axes[N], old_axes[Ns::value]...});
+ return std::decay_t<decltype(old_axes)>({old_axes[N], old_axes[Ns::value]...});
},
old_axes);
@@ -50,7 +53,7 @@ auto project(const histogram<A, S>& h, std::integral_constant<unsigned, N>, Ns..
using A2 = decltype(axes);
auto result = histogram<A2, S>(std::move(axes), detail::make_default(old_storage));
auto idx = detail::make_stack_buffer<int>(unsafe_access::axes(result));
- for (auto x : indexed(h, coverage::all)) {
+ for (auto&& x : indexed(h, coverage::all)) {
auto i = idx.begin();
mp11::mp_for_each<LN>([&i, &x](auto J) { *i++ = x.index(J); });
result.at(idx) += *x;
@@ -66,23 +69,24 @@ auto project(const histogram<A, S>& h, std::integral_constant<unsigned, N>, Ns..
*/
template <class A, class S, class Iterable, class = detail::requires_iterable<Iterable>>
auto project(const histogram<A, S>& h, const Iterable& c) {
- static_assert(detail::is_sequence_of_any_axis<A>::value,
- "this version of project requires histogram with non-static axes");
-
+ using namespace boost::mp11;
const auto& old_axes = unsafe_access::axes(h);
- auto axes = detail::make_default(old_axes);
+
+ // axes is always std::vector<...>, even if A is tuple
+ auto axes = detail::make_empty_dynamic_axes(old_axes);
axes.reserve(c.size());
auto seen = detail::make_stack_buffer<bool>(old_axes, false);
for (auto d : c) {
if (seen[d]) BOOST_THROW_EXCEPTION(std::invalid_argument("indices must be unique"));
seen[d] = true;
- axes.emplace_back(old_axes[d]);
+ axes.emplace_back(detail::axis_get(old_axes, d));
}
const auto& old_storage = unsafe_access::storage(h);
- auto result = histogram<A, S>(std::move(axes), detail::make_default(old_storage));
+ auto result =
+ histogram<decltype(axes), S>(std::move(axes), detail::make_default(old_storage));
auto idx = detail::make_stack_buffer<int>(unsafe_access::axes(result));
- for (auto x : indexed(h, coverage::all)) {
+ for (auto&& x : indexed(h, coverage::all)) {
auto i = idx.begin();
for (auto d : c) *i++ = x.index(d);
result.at(idx) += *x;