From a2cb137b93c1fdba76bf95246c958e864a4ed45c Mon Sep 17 00:00:00 2001 From: Hans Dembinski Date: Sat, 3 Nov 2018 17:06:34 +0100 Subject: [PATCH] fix --- .clang-format | 7 +- examples/guide_fill_histogram.cpp | 10 +- include/boost/histogram/detail/axes.hpp | 160 ++++++++++++------------ 3 files changed, 89 insertions(+), 88 deletions(-) diff --git a/.clang-format b/.clang-format index c9d871a7..a8d16367 100644 --- a/.clang-format +++ b/.clang-format @@ -7,15 +7,14 @@ AlignConsecutiveDeclarations: false AlignEscapedNewlinesLeft: true AlignOperands: true AlignTrailingComments: true -AllowAllParametersOfDeclarationOnNextLine: true +AllowAllParametersOfDeclarationOnNextLine: false AllowShortBlocksOnASingleLine: true -AllowShortCaseLabelsOnASingleLine: false +AllowShortCaseLabelsOnASingleLine: true AllowShortFunctionsOnASingleLine: All AllowShortIfStatementsOnASingleLine: true AllowShortLoopsOnASingleLine: true -AlwaysBreakAfterDefinitionReturnType: None AlwaysBreakAfterReturnType: None -AlwaysBreakBeforeMultilineStrings: true +AlwaysBreakBeforeMultilineStrings: false AlwaysBreakTemplateDeclarations: true BinPackArguments: true BinPackParameters: true diff --git a/examples/guide_fill_histogram.cpp b/examples/guide_fill_histogram.cpp index c305b817..c49b2b18 100644 --- a/examples/guide_fill_histogram.cpp +++ b/examples/guide_fill_histogram.cpp @@ -1,3 +1,4 @@ +// clang-format off //[ guide_fill_histogram #include @@ -10,8 +11,8 @@ namespace bh = boost::histogram; int main() { - auto h = - bh::make_histogram(bh::axis::regular<>(8, 0, 4), bh::axis::regular<>(10, 0, 5)); + auto h = bh::make_histogram(bh::axis::regular<>(8, 0, 4), + bh::axis::regular<>(10, 0, 5)); // fill histogram, number of arguments must be equal to number of axes h(0, 1.1); // increases bin counter by one @@ -30,8 +31,9 @@ int main() { // std::for_each takes the functor by value, we use a reference wrapper // here to avoid costly copies - auto h2 = - bh::make_histogram(bh::axis::regular<>(8, 0, 4), bh::axis::regular<>(10, 0, 5)); + auto h2 = bh::make_histogram(bh::axis::regular<>(8, 0, 4), + bh::axis::regular<>(10, 0, 5)); + std::for_each(input_data.begin(), input_data.end(), std::ref(h2)); // h2 is filled diff --git a/include/boost/histogram/detail/axes.hpp b/include/boost/histogram/detail/axes.hpp index a34d159e..871f4773 100644 --- a/include/boost/histogram/detail/axes.hpp +++ b/include/boost/histogram/detail/axes.hpp @@ -24,86 +24,6 @@ namespace boost { namespace histogram { namespace detail { -template -bool axes_equal(const std::tuple& t, const std::tuple& u) { - return static_if, mp11::mp_list>>( - [](const auto& a, const auto& b) { return a == b; }, - [](const auto&, const auto&) { return false; }, t, u); -} - -template -bool axes_equal(const std::tuple& t, const U& u) { - if (sizeof...(Ts) != u.size()) return false; - bool equal = true; - mp11::mp_for_each>([&](auto I) { - using T = mp11::mp_at, decltype(I)>; - auto up = axis::get(&u[I]); - equal &= (up && std::get(t) == *up); - }); - return equal; -} - -template -bool axes_equal(const T& t, const std::tuple& u) { - return axes_equal(u, t); -} - -template -bool axes_equal(const T& t, const U& u) { - if (t.size() != u.size()) return false; - return std::equal(t.begin(), t.end(), u.begin()); -} - -template -void axes_assign(std::tuple& t, const std::tuple& u) { - t = u; -} - -template -void axes_assign(std::tuple&, const std::tuple&) { - throw std::invalid_argument("cannot assign axes if types do not match"); -} - -template -void axes_assign(std::tuple& t, const U& u) { - mp11::mp_for_each>([&](auto I) { - using T = mp11::mp_at_c, I>; - std::get(t) = axis::get(u[I]); - }); -} - -template -void axes_assign(T& t, const std::tuple& u) { - t.resize(sizeof...(Us)); - mp11::mp_for_each>( - [&](auto I) { t[I] = std::get(u); }); -} - -template -void axes_assign(T& t, const U& u) { - t.assign(u.begin(), u.end()); -} - -template -constexpr std::size_t axes_size(const std::tuple&) { - return sizeof...(Ts); -} - -template -std::size_t axes_size(const T& axes) { - return axes.size(); -} - -template -void range_check(const std::tuple&) { - static_assert(N < sizeof...(Ts), "index out of range"); -} - -template -void range_check(const T& axes) { - BOOST_ASSERT_MSG(N < axes.size(), "index out of range"); -} - template decltype(auto) axis_get(std::tuple& axes) { return std::get(axes); @@ -146,6 +66,86 @@ decltype(auto) axis_get(const T& axes, std::size_t i) { return axes.at(i); } +template +bool axes_equal(const std::tuple& t, const std::tuple& u) { + return static_if, mp11::mp_list>>( + [](const auto& a, const auto& b) { return a == b; }, + [](const auto&, const auto&) { return false; }, t, u); +} + +template +bool axes_equal(const std::tuple& t, const U& u) { + if (sizeof...(Ts) != u.size()) return false; + bool equal = true; + mp11::mp_for_each>([&](auto I) { + using T = mp11::mp_at, decltype(I)>; + auto up = axis::get(&u[I]); + equal &= (up && std::get(t) == *up); + }); + return equal; +} + +template +bool axes_equal(const T& t, const std::tuple& u) { + return axes_equal(u, t); +} + +template +bool axes_equal(const T& t, const U& u) { + if (t.size() != u.size()) return false; + return std::equal(t.begin(), t.end(), u.begin()); +} + +template +void axes_assign(std::tuple& t, const std::tuple& u) { + static_if, mp11::mp_list>>( + [](auto& a, const auto& b) { a = b; }, + [](auto&, const auto&) { + throw std::invalid_argument("cannot assign axes, types do not match"); + }, + t, u); +} + +template +void axes_assign(std::tuple& t, const U& u) { + mp11::mp_for_each>([&](auto I) { + using T = mp11::mp_at_c, I>; + std::get(t) = axis::get(u[I]); + }); +} + +template +void axes_assign(T& t, const std::tuple& u) { + t.resize(sizeof...(Us)); + mp11::mp_for_each>( + [&](auto I) { t[I] = std::get(u); }); +} + +template +void axes_assign(T& t, const U& u) { + t.assign(u.begin(), u.end()); +} + +template +constexpr std::size_t axes_size(const std::tuple&) { + return sizeof...(Ts); +} + +template +std::size_t axes_size(const T& axes) { + return axes.size(); +} + +template +void range_check(const std::tuple&) { + static_assert(N < sizeof...(Ts), "index out of range"); +} + +template +void range_check(const T& axes) { + BOOST_ASSERT_MSG(N < axes.size(), "index out of range"); +} + template void for_each_axis(const std::tuple& axes, F&& f) { mp11::tuple_for_each(axes, std::forward(f));