diff --git a/examples/getting_started_listing_02.cpp b/examples/getting_started_listing_02.cpp index 663b4909..bfb32e47 100644 --- a/examples/getting_started_listing_02.cpp +++ b/examples/getting_started_listing_02.cpp @@ -16,7 +16,7 @@ int main() { - in addition, the factory also accepts iterators over a sequence of axis::any, the polymorphic type that can hold concrete axis types */ - std::vector axes; + std::vector axes; axes.emplace_back(bh::axis::category({"red", "blue"})); axes.emplace_back(bh::axis::regular<>(5, -5, 5, "x")); axes.emplace_back(bh::axis::regular<>(5, -5, 5, "y")); diff --git a/examples/guide_make_dynamic_histogram.cpp b/examples/guide_make_dynamic_histogram.cpp index 603f0325..39cfb7c4 100644 --- a/examples/guide_make_dynamic_histogram.cpp +++ b/examples/guide_make_dynamic_histogram.cpp @@ -7,7 +7,7 @@ namespace bh = boost::histogram; int main() { // create vector of axes, axis::any is a polymorphic axis type - auto v = std::vector(); + auto v = std::vector(); v.push_back(bh::axis::regular<>(100, -1, 1)); v.push_back(bh::axis::integer<>(1, 7)); diff --git a/include/boost/histogram/axis/any.hpp b/include/boost/histogram/axis/any.hpp index 2302aaea..b2dd3890 100644 --- a/include/boost/histogram/axis/any.hpp +++ b/include/boost/histogram/axis/any.hpp @@ -32,33 +32,35 @@ namespace histogram { namespace axis { namespace detail { -struct size : public static_visitor { +using ::boost::histogram::detail::rm_cv_ref; + +struct size_visitor : public static_visitor { template int operator()(const A &a) const { return a.size(); } }; -struct shape : public static_visitor { +struct shape_visitor : public static_visitor { template int operator()(const A &a) const { return a.shape(); } }; -struct uoflow : public static_visitor { +struct uoflow_visitor : public static_visitor { template bool operator()(const A &a) const { return a.uoflow(); } }; -struct get_label : public static_visitor { +struct get_label_visitor : public static_visitor { template ::boost::string_view operator()(const A &a) const { return a.label(); } }; -struct set_label : public static_visitor { +struct set_label_visitor : public static_visitor { const ::boost::string_view label; - set_label(const ::boost::string_view x) : label(x) {} + set_label_visitor(const ::boost::string_view x) : label(x) {} template void operator()(A &a) const { a.label(label); } }; -struct index : public static_visitor { +struct index_visitor : public static_visitor { const double x; - explicit index(const double arg) : x(arg) {} + explicit index_visitor(const double arg) : x(arg) {} template int operator()(const Axis &a) const { return impl(std::is_convertible(), a); } @@ -73,9 +75,9 @@ struct index : public static_visitor { } }; -struct lower : public static_visitor { +struct lower_visitor : public static_visitor { int idx; - lower(int i) : idx(i) {} + lower_visitor(int i) : idx(i) {} template double operator()(const Axis &a) const { return impl( std::integral_constant< @@ -96,7 +98,7 @@ struct lower : public static_visitor { } }; -struct bicmp : public static_visitor { +struct bicmp_visitor : public static_visitor { template bool operator()(const T&, const U&) const { return false; } @@ -106,6 +108,44 @@ struct bicmp : public static_visitor { } }; +template +struct cmp_visitor : public static_visitor { + const T& t; + cmp_visitor(const T& tt) : t(tt) {} + template bool operator()(const U& u) const { + return impl(mp11::mp_same(), u); + } + + template bool impl(mp11::mp_true, const U& u) const { + return t == u; + } + + template bool impl(mp11::mp_false, const U&) const { + return false; + } +}; + +template +struct assign_visitor : public static_visitor { + T& t; + assign_visitor(T& tt) : t(tt) {} + template void operator()(const U& u) const { + impl(mp11::mp_contains(), u); + } + + template void impl(mp11::mp_true, const U& u) const { + t = u; + } + + template void impl(mp11::mp_false, const U&) const { + throw std::invalid_argument(::boost::histogram::detail::cat( + "argument ", + boost::typeindex::type_id().pretty_name(), + " is not a bounded type of ", + boost::typeindex::type_id().pretty_name())); + } +}; + } // namespace detail /// Polymorphic axis type @@ -120,62 +160,60 @@ public: using const_reverse_iterator = reverse_iterator_over; private: - template using requires_bounded_type = mp11::mp_if, void>; + template using requires_bounded_type = mp11::mp_if< + mp11::mp_contains + >, void>; public: any() = default; any(const any&) = default; any& operator=(const any&) = default; - // any(any&&) = default; - // any& operator=(any&&) = default; - - template - any(const any &) {} // TODO - - template - any &operator=(const any &) { // TODO - return *this; - } + any(any&&) = default; + any& operator=(any&&) = default; template > - any(const T& ) {} // TODO + any(T&& t) : base_type(std::forward(t)) {} - template - any& operator=(const T&) { + template > + any& operator=(T&& t) { + base_type::operator=(std::forward(t)); return *this; } - // template - // any(any &&t) {} // TODO + template + any(const any & u) { + apply_visitor(detail::assign_visitor(*this), u); + } - // template - // any &operator=(any &&t) { // TODO - // return *this; - // } + template + any &operator=(const any & u) { + apply_visitor(detail::assign_visitor(*this), u); + return *this; + } - int size() const { return apply_visitor(detail::size(), *this); } + int size() const { return apply_visitor(detail::size_visitor(), *this); } - int shape() const { return apply_visitor(detail::shape(), *this); } + int shape() const { return apply_visitor(detail::shape_visitor(), *this); } - bool uoflow() const { return apply_visitor(detail::uoflow(), *this); } + bool uoflow() const { return apply_visitor(detail::uoflow_visitor(), *this); } // note: this only works for axes with compatible value type int index(const value_type x) const { - return apply_visitor(detail::index(x), *this); + return apply_visitor(detail::index_visitor(x), *this); } string_view label() const { - return apply_visitor(detail::get_label(), *this); + return apply_visitor(detail::get_label_visitor(), *this); } void label(const string_view x) { - return apply_visitor(detail::set_label(x), *this); + return apply_visitor(detail::set_label_visitor(x), *this); } // this only works for axes with compatible bin type // and will throw a runtime_error otherwise double lower(int idx) const { - return apply_visitor(detail::lower(idx), *this); + return apply_visitor(detail::lower_visitor(idx), *this); } bin_type operator[](const int idx) const { return bin_type(idx, *this); } @@ -185,13 +223,14 @@ public: } template - bool operator==(const any& rhs) const { - return apply_visitor(detail::bicmp(), *this, rhs); + bool operator==(const any& u) const { + return apply_visitor(detail::bicmp_visitor(), *this, u); } template > - bool operator==(const T &) const { // TODO - return false; + bool operator==(const T & t) const { + // variant::operator==(T) is implemented, but only to fail, cannot use it + return apply_visitor(detail::cmp_visitor(t), *this); } const_iterator begin() const { return const_iterator(*this, 0); } @@ -229,24 +268,10 @@ const typename std::add_pointer::type cast(const any *any) { return get(&any); } -// pass-through versions for generic programming, i.e. when you switch to static -// histogram -template typename std::add_lvalue_reference::type cast(T &t) { - return t; -} - -template -const typename std::add_lvalue_reference::type cast(const T &t) { - return t; -} - -template typename std::add_pointer::type cast(T *t) { - return t; -} - -template -const typename std::add_pointer::type cast(const T *t) { - return t; +// pass-through for generic programming, to keep code workgin when +// you switch from dynamic to static histogram +template auto cast(U && u) -> decltype(std::forward(u)) { + return std::forward(u); } } // namespace axis diff --git a/include/boost/histogram/detail/meta.hpp b/include/boost/histogram/detail/meta.hpp index ff496eeb..bea3d143 100644 --- a/include/boost/histogram/detail/meta.hpp +++ b/include/boost/histogram/detail/meta.hpp @@ -21,7 +21,7 @@ namespace histogram { namespace detail { #define BOOST_HISTOGRAM_MAKE_SFINAE(name, cond) \ -template struct name { \ +template struct name##_impl { \ template \ struct SFINAE {}; \ template static std::true_type Test(SFINAE *); \ @@ -29,7 +29,7 @@ template struct name { \ using type = decltype(Test(nullptr)); \ }; \ template \ -using name##_t = typename name::type +using name = typename name##_impl::type BOOST_HISTOGRAM_MAKE_SFINAE(has_variance_support, (std::declval().value(), std::declval().variance())); @@ -51,12 +51,12 @@ struct dynamic_container_tag {}; struct no_container_tag {}; template -using classify_container_t = +using classify_container = typename std::conditional< - is_static_container_t::value, + is_static_container::value, static_container_tag, typename std::conditional< - is_dynamic_container_t::value, + is_dynamic_container::value, dynamic_container_tag, no_container_tag >::type @@ -73,10 +73,10 @@ struct requires_iterator {}; template using requires_axis = decltype(std::declval().size(), - std::declval().shape(), - std::declval().uoflow(), - std::declval().label(), - std::declval()[0]); + std::declval().shape(), + std::declval().uoflow(), + std::declval().label(), + std::declval()[0]); namespace { struct bool_mask_impl { @@ -93,11 +93,15 @@ std::vector bool_mask(unsigned n, bool v) { return b; } -template -using size_of = std::tuple_size::type>; +template using rm_cv_ref = typename std::remove_cv< + typename std::remove_reference::type>::type; -template -using type_of = typename std::tuple_element::type>::type; +template using mp_size = mp11::mp_size>; + +template using mp_at_c = mp11::mp_at_c, D>; + +template +using mp_union = mp11::mp_rename, mp11::mp_set_push_back>; namespace { template diff --git a/include/boost/histogram/detail/utility.hpp b/include/boost/histogram/detail/utility.hpp index 5783f6e4..67993651 100644 --- a/include/boost/histogram/detail/utility.hpp +++ b/include/boost/histogram/detail/utility.hpp @@ -98,11 +98,11 @@ private: }; template -typename std::enable_if<(is_castable_to_int_t::value), int>::type +typename std::enable_if<(is_castable_to_int::value), int>::type indirect_int_cast(T&&t) noexcept { return static_cast(std::forward(t)); } template -typename std::enable_if::value), int>::type +typename std::enable_if::value), int>::type indirect_int_cast(T&&) noexcept { // Cannot use static_assert here, because this function is created as a // side-effect of TMP. It must be valid at compile-time. diff --git a/include/boost/histogram/dynamic_histogram.hpp b/include/boost/histogram/dynamic_histogram.hpp index 533c2011..ee33c670 100644 --- a/include/boost/histogram/dynamic_histogram.hpp +++ b/include/boost/histogram/dynamic_histogram.hpp @@ -153,7 +153,7 @@ public: if (dim() == 1) { fill_impl(detail::no_container_tag(), std::forward(t)); } else { - fill_impl(detail::classify_container_t(), std::forward(t)); + fill_impl(detail::classify_container(), std::forward(t)); } } @@ -175,7 +175,7 @@ public: if (dim() == 1) { fill_impl(detail::no_container_tag(), std::forward(t), std::move(w)); } else { - fill_impl(detail::classify_container_t(), std::forward(t), std::move(w)); + fill_impl(detail::classify_container(), std::forward(t), std::move(w)); } } @@ -194,13 +194,13 @@ public: template const_reference at(T&&t) const { // check whether T is unpackable - return at_impl(detail::classify_container_t(), std::forward(t)); + return at_impl(detail::classify_container(), std::forward(t)); } template const_reference operator[](T&&t) const { // check whether T is unpackable - return at_impl(detail::classify_container_t(), std::forward(t)); + return at_impl(detail::classify_container(), std::forward(t)); } /// Number of axes (dimensions) of histogram @@ -296,10 +296,10 @@ private: template void fill_impl(detail::static_container_tag, T && t, Ts&&... ts) { - BOOST_ASSERT_MSG(dim() == detail::size_of::value, + BOOST_ASSERT_MSG(dim() == detail::mp_size::value, "fill container does not match histogram dimension"); std::size_t idx = 0, stride = 1; - xlin_get(mp11::mp_int::value>(), idx, stride, std::forward(t)); + xlin_get(mp11::mp_int::value>(), idx, stride, std::forward(t)); if (stride) { fill_storage_impl(idx, std::forward(ts)...); } @@ -329,10 +329,10 @@ private: template const_reference at_impl(detail::static_container_tag, T && t) const { - BOOST_ASSERT_MSG(dim() == detail::size_of::value, + BOOST_ASSERT_MSG(dim() == detail::mp_size::value, "bin container does not match histogram dimension"); std::size_t idx = 0, stride = 1; - lin_get(mp11::mp_int::value>(), idx, stride, std::forward(t)); + lin_get(mp11::mp_int::value>(), idx, stride, std::forward(t)); if (stride == 0) throw std::out_of_range("bin index out of range"); return storage_[idx]; @@ -428,8 +428,8 @@ private: template void xlin_get(mp11::mp_int, std::size_t& idx, std::size_t & stride, T&&t) const { - constexpr unsigned D = detail::size_of::value - N; - apply_visitor(xlin_visitor>{idx, stride, std::get(t)}, axes_[D]); + constexpr unsigned D = detail::mp_size::value - N; + apply_visitor(xlin_visitor>{idx, stride, std::get(t)}, axes_[D]); xlin_get(mp11::mp_int<(N-1)>(), idx, stride, std::forward(t)); } @@ -438,7 +438,7 @@ private: template void lin_get(mp11::mp_int, std::size_t& idx, std::size_t & stride, T&&t) const noexcept { - constexpr unsigned D = detail::size_of::value - N; + constexpr unsigned D = detail::mp_size::value - N; apply_visitor(lin_visitor{idx, stride, static_cast(std::get(t))}, axes_[D]); lin_get(mp11::mp_int<(N-1)>(), idx, stride, std::forward(t)); } @@ -471,45 +471,36 @@ private: template dynamic_histogram< - mp11::mp_set_push_back + mp11::mp_set_push_back...> > make_dynamic_histogram(Axis &&... axis) { using H = dynamic_histogram< - mp11::mp_set_push_back + mp11::mp_set_push_back...> >; return H(std::forward(axis)...); } -template +template dynamic_histogram< - mp11::mp_set_push_back, + mp11::mp_set_push_back...>, Storage > -make_dynamic_histogram_with(Axes &&... axes) { +make_dynamic_histogram_with(Axis &&... axis) { using H = dynamic_histogram< - mp11::mp_set_push_back, + mp11::mp_set_push_back...>, Storage >; - return H(std::forward(axes)...); + return H(std::forward(axis)...); } -template > +template > dynamic_histogram< - mp11::mp_unique< - mp11::mp_append< - axis::builtins, - typename Iterator::value_type::types - > - > + detail::mp_union > make_dynamic_histogram(Iterator begin, Iterator end) { using H = dynamic_histogram< - mp11::mp_unique< - mp11::mp_append< - axis::builtins, - typename Iterator::value_type::types - > - > + detail::mp_union >; return H(begin, end); } @@ -517,35 +508,35 @@ make_dynamic_histogram(Iterator begin, Iterator end) { // template // dynamic_histogram< -// detail::union_t>, +// detail::union_t>, // array_storage>> // make_dynamic_weighted_histogram(Axes &&... axes) { // return dynamic_histogram, -// detail::union_t>, +// detail::union_t>, // array_storage>>( // std::forward(axes)...); // } // template > // dynamic_histogram, -// detail::union_t, +// detail::union_t, // array_storage>> // make_dynamic_weighted_histogram(Iterator begin, Iterator end) { // return histogram< // dynamic_tag, -// detail::union_t, +// detail::union_t, // array_storage>>(begin, end); // } // template > // dynamic_histogram, -// detail::union_t, +// detail::union_t, // Storage> // make_dynamic_histogram_with(Iterator begin, Iterator end) { // return histogram< // dynamic_tag, -// detail::union_t, +// detail::union_t, // Storage>(begin, end); // } diff --git a/include/boost/histogram/histogram_fwd.hpp b/include/boost/histogram/histogram_fwd.hpp index 0b79429e..3ce018b1 100644 --- a/include/boost/histogram/histogram_fwd.hpp +++ b/include/boost/histogram/histogram_fwd.hpp @@ -33,18 +33,17 @@ template class variable; template class integer; template class category; -using builtins = +using types = mp11::mp_list, - axis::regular, - axis::regular, - axis::regular, - axis::circular, axis::variable, - axis::integer, axis::category, - axis::category>; + axis::regular, + axis::regular, + axis::regular, + axis::circular, axis::variable, + axis::integer, axis::category, + axis::category>; template class any; - -using any_builtin = mp11::mp_rename; +using any_std = mp11::mp_rename; } // namespace axis @@ -53,7 +52,7 @@ struct static_tag {}; template class histogram; -template +template using dynamic_histogram = histogram; template diff --git a/include/boost/histogram/static_histogram.hpp b/include/boost/histogram/static_histogram.hpp index bb07f040..6dbb04d7 100644 --- a/include/boost/histogram/static_histogram.hpp +++ b/include/boost/histogram/static_histogram.hpp @@ -149,7 +149,7 @@ public: // check whether we need to unpack argument fill_impl(mp11::mp_if_c<(axes_size::value == 1), detail::no_container_tag, - detail::classify_container_t>(), std::forward(t)); + detail::classify_container>(), std::forward(t)); } // TODO: merge this with unpacking @@ -168,7 +168,7 @@ public: // check whether we need to unpack argument fill_impl(mp11::mp_if_c<(axes_size::value == 1), detail::no_container_tag, - detail::classify_container_t>(), std::forward(t), std::move(w)); + detail::classify_container>(), std::forward(t), std::move(w)); } template @@ -186,13 +186,13 @@ public: template const_reference operator[](T&&t) const { // check whether we need to unpack argument - return at_impl(detail::classify_container_t(), std::forward(t)); + return at_impl(detail::classify_container(), std::forward(t)); } template const_reference at(T&&t) const { // check whether we need to unpack argument - return at_impl(detail::classify_container_t(), std::forward(t)); + return at_impl(detail::classify_container(), std::forward(t)); } /// Number of axes (dimensions) of histogram @@ -296,7 +296,7 @@ private: template void fill_impl(detail::static_container_tag, T&&t, Ts&&...ts) { - static_assert(detail::size_of::value == axes_size::value, + static_assert(detail::mp_size::value == axes_size::value, "fill container does not match histogram dimension"); std::size_t idx = 0, stride = 1; xlin_get(axes_size(), idx, stride, std::forward(t)); @@ -405,7 +405,7 @@ private: template void xlin_get(mp11::mp_size_t, std::size_t &idx, std::size_t &stride, T && t) const { - constexpr unsigned D = detail::size_of::value - N; + constexpr unsigned D = detail::mp_size::value - N; const auto a_size = std::get(axes_).size(); const auto a_shape = std::get(axes_).shape(); const auto j = std::get(axes_).index(std::get(t)); @@ -418,7 +418,7 @@ private: template void lin_get(mp11::mp_size_t, std::size_t &idx, std::size_t &stride, T&&t) const noexcept { - constexpr unsigned D = detail::size_of::value - N; + constexpr unsigned D = detail::mp_size::value - N; const auto a_size = std::get(axes_).size(); const auto a_shape = std::get(axes_).shape(); const auto j = detail::indirect_int_cast(std::get(t)); diff --git a/test/axis_size.cpp b/test/axis_size.cpp deleted file mode 100644 index 8941fcba..00000000 --- a/test/axis_size.cpp +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright 2015-2017 Hans Dembinski -// -// Distributed under the Boost Software License, Version 1.0. -// (See accompanying file LICENSE_1_0.txt -// or copy at http://www.boost.org/LICENSE_1_0.txt) - -#include -#include -#include -#include -#include - -namespace boost { namespace histogram { - using axis_variant = - typename make_variant_over::type; -}} - -int main() { - -#define SIZEOF(axis) \ - std::cout << #axis << " " << sizeof(boost::histogram::axis) << std::endl -SIZEOF(axis::regular<>); -SIZEOF(axis::circular<>); -SIZEOF(axis::variable<>); -SIZEOF(axis::integer<>); -SIZEOF(axis::category<>); -SIZEOF(axis::any<>); - -} diff --git a/test/axis_test.cpp b/test/axis_test.cpp index 7d0a0bc5..89214660 100644 --- a/test/axis_test.cpp +++ b/test/axis_test.cpp @@ -37,7 +37,16 @@ void test_axis_iterator(const Axis &a, int begin, int end) { } int main() { - using any_axis = boost::mp11::mp_rename; + + // sizes + { + BOOST_TEST_EQ(sizeof(axis::regular<>), 64); + BOOST_TEST_EQ(sizeof(axis::circular<>), 56); + BOOST_TEST_EQ(sizeof(axis::variable<>), 56); + BOOST_TEST_EQ(sizeof(axis::integer<>), 48); + BOOST_TEST_EQ(sizeof(axis::category<>), 48); + BOOST_TEST_EQ(sizeof(axis::any_std), 80); + } // bad_ctors { @@ -240,40 +249,40 @@ int main() { test_axis_iterator(axis::variable<>({1, 2, 3}, ""), 0, 2); test_axis_iterator(axis::integer<>(0, 4, ""), 0, 4); test_axis_iterator(axis::category<>({A, B, C}, ""), 0, 3); - test_axis_iterator(any_axis(axis::regular<>(5, 0, 1)), 0, 5); - BOOST_TEST_THROWS(any_axis(axis::category<>({A, B, C})).lower(0), + test_axis_iterator(axis::any_std(axis::regular<>(5, 0, 1)), 0, 5); + BOOST_TEST_THROWS(axis::any_std(axis::category<>({A, B, C})).lower(0), std::runtime_error); } - // any_axis_type_copyable + // any_std_type_copyable { - any_axis a(axis::regular<>(2, -1, 1)); - any_axis b(a); + axis::any_std a(axis::regular<>(2, -1, 1)); + axis::any_std b(a); BOOST_TEST(a == b); - any_axis c; + axis::any_std c; BOOST_TEST_NOT(a == c); c = a; BOOST_TEST(a == c); } - // any_axis_type_movable + // any_std_type_movable { - any_axis a(axis::regular<>(2, -1, 1)); - any_axis r(a); - any_axis b(std::move(a)); + axis::any_std a(axis::regular<>(2, -1, 1)); + axis::any_std r(a); + axis::any_std b(std::move(a)); BOOST_TEST_EQ(b, r); - any_axis c; + axis::any_std c; BOOST_TEST_NOT(a == c); c = std::move(b); BOOST_TEST(c == r); } - // any_axis_type_streamable + // any_std_type_streamable { enum { A, B, C }; std::string a = "A"; std::string b = "B"; - std::vector axes; + std::vector axes; axes.push_back(axis::regular<>{2, -1, 1, "regular1"}); axes.push_back(axis::regular( 2, 1, 10, "regular2", axis::uoflow::off)); @@ -303,27 +312,27 @@ int main() { BOOST_TEST_EQ(os.str(), ref); } - // any_axis_type_equal_comparable + // any_std_type_equal_comparable { enum { A, B, C }; - std::vector axes; + std::vector axes; axes.push_back(axis::regular<>{2, -1, 1}); axes.push_back(axis::circular<>{4}); axes.push_back(axis::variable<>{-1, 0, 1}); axes.push_back(axis::category<>{A, B, C}); axes.push_back(axis::integer<>{-1, 1}); for (const auto &a : axes) { - BOOST_TEST(!(a == any_axis())); + BOOST_TEST(!(a == axis::any_std())); BOOST_TEST_EQ(a, a); } - BOOST_TEST_NOT(axes == std::vector()); - BOOST_TEST(axes == std::vector(axes)); + BOOST_TEST_NOT(axes == std::vector()); + BOOST_TEST(axes == std::vector(axes)); } - // any_axis_type_value_to_index_failure + // any_std_type_value_to_index_failure { std::string a = "A", b = "B"; - any_axis x = axis::category({a, b}, "category"); + axis::any_std x = axis::category({a, b}, "category"); BOOST_TEST_THROWS(x.index(1.5), std::runtime_error); const auto &cx = axis::cast>(x); BOOST_TEST_EQ(cx.index(b), 1); diff --git a/test/detail_test.cpp b/test/detail_test.cpp index f145a50a..105ab017 100644 --- a/test/detail_test.cpp +++ b/test/detail_test.cpp @@ -149,35 +149,35 @@ int main() { const double &variance() const; }; - BOOST_TEST_EQ(has_variance_support_t(), false); - BOOST_TEST_EQ(has_variance_support_t(), false); - BOOST_TEST_EQ(has_variance_support_t(), + BOOST_TEST_EQ(has_variance_support(), false); + BOOST_TEST_EQ(has_variance_support(), false); + BOOST_TEST_EQ(has_variance_support(), false); - BOOST_TEST_EQ(has_variance_support_t(), + BOOST_TEST_EQ(has_variance_support(), true); } // classify_container { - using result1 = classify_container_t; + using result1 = classify_container; BOOST_TEST_TRAIT_TRUE(( std::is_same )); - using result1a = classify_container_t; + using result1a = classify_container; BOOST_TEST_TRAIT_TRUE(( std::is_same )); - using result2 = classify_container_t>; + using result2 = classify_container>; BOOST_TEST_TRAIT_TRUE(( std::is_same )); - using result2a = classify_container_t&>; + using result2a = classify_container&>; BOOST_TEST_TRAIT_TRUE(( std::is_same )); - using result3 = classify_container_t>; + using result3 = classify_container>; BOOST_TEST_TRAIT_TRUE(( std::is_same )); - using result3a = classify_container_t&>; + using result3a = classify_container&>; BOOST_TEST_TRAIT_TRUE(( std::is_same )); - using result4 = classify_container_t; + using result4 = classify_container; BOOST_TEST_TRAIT_TRUE(( std::is_same )); } @@ -190,6 +190,31 @@ int main() { BOOST_TEST_EQ(v2, std::vector({false, true, false, true})); } + // rm_cv_ref + { + using T1 = int; + using T2 = const int; + using T3 = const int&; + using T4 = volatile int; + using T5 = volatile const int; + using T6 = volatile const int&; + BOOST_TEST_TRAIT_TRUE((std::is_same, int>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, int>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, int>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, int>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, int>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, int>)); + } + + // mp_union + { + using L1 = mp11::mp_list; + using L2 = mp11::mp_list; + using result = mp_union; + using expected = mp11::mp_list; + BOOST_TEST_TRAIT_TRUE((std::is_same)); + } + // literals { auto j0 = 0_c; diff --git a/test/histogram_test.cpp b/test/histogram_test.cpp index f19b163e..16856cde 100644 --- a/test/histogram_test.cpp +++ b/test/histogram_test.cpp @@ -44,16 +44,6 @@ auto make_histogram(dynamic_tag, Axes &&... axes) return make_dynamic_histogram_with(std::forward(axes)...); } -template -bool axis_equal(static_tag, const T &t, const U &u) { - return t == u; -} - -template -bool axis_equal(dynamic_tag, const T &t, const U &u) { - return t == u; // need to convert rhs to boost::variant -} - int expected_moved_from_dim(static_tag, int static_value) { return static_value; } @@ -635,7 +625,7 @@ template void run_tests() { BOOST_TEST_EQ(h1_0.at(1), 3); BOOST_TEST_EQ(h1_0.axis()[0].lower(), 0); BOOST_TEST_EQ(h1_0.axis()[1].lower(), 1); - BOOST_TEST(axis_equal(Type(), h1_0.axis(), h1.axis(0_c))); + BOOST_TEST(h1_0.axis() == h1.axis(0_c)); auto h1_1 = h1.reduce_to(1_c); BOOST_TEST_EQ(h1_1.dim(), 1); @@ -643,7 +633,7 @@ template void run_tests() { BOOST_TEST_EQ(h1_1.at(0), 2); BOOST_TEST_EQ(h1_1.at(1), 2); BOOST_TEST_EQ(h1_1.at(2), 1); - BOOST_TEST(axis_equal(Type(), h1_1.axis(), h1.axis(1_c))); + BOOST_TEST(h1_1.axis() == h1.axis(1_c)); auto h2 = make_histogram(Type(), axis::integer<>(0, 2), axis::integer<>(0, 3), @@ -659,14 +649,14 @@ template void run_tests() { BOOST_TEST_EQ(sum(h2_0), 5); BOOST_TEST_EQ(h2_0.at(0), 4); BOOST_TEST_EQ(h2_0.at(1), 1); - BOOST_TEST(axis_equal(Type(), h2_0.axis(), axis::integer<>(0, 2))); + BOOST_TEST(h2_0.axis() == axis::integer<>(0, 2)); auto h2_1 = h2.reduce_to(1_c); BOOST_TEST_EQ(h2_1.dim(), 1); BOOST_TEST_EQ(sum(h2_1), 5); BOOST_TEST_EQ(h2_1.at(0), 3); BOOST_TEST_EQ(h2_1.at(1), 2); - BOOST_TEST(axis_equal(Type(), h2_1.axis(), axis::integer<>(0, 3))); + BOOST_TEST(h2_1.axis() == axis::integer<>(0, 3)); auto h2_2 = h2.reduce_to(2_c); BOOST_TEST_EQ(h2_2.dim(), 1); @@ -674,7 +664,7 @@ template void run_tests() { BOOST_TEST_EQ(h2_2.at(0), 2); BOOST_TEST_EQ(h2_2.at(1), 1); BOOST_TEST_EQ(h2_2.at(2), 2); - BOOST_TEST(axis_equal(Type(), h2_2.axis(), axis::integer<>(0, 4))); + BOOST_TEST(h2_2.axis() == axis::integer<>(0, 4)); auto h2_01 = h2.reduce_to(0_c, 1_c); BOOST_TEST_EQ(h2_01.dim(), 2); @@ -682,8 +672,8 @@ template void run_tests() { BOOST_TEST_EQ(h2_01.at(0, 0), 2); BOOST_TEST_EQ(h2_01.at(0, 1), 2); BOOST_TEST_EQ(h2_01.at(1, 0), 1); - BOOST_TEST(axis_equal(Type(), h2_01.axis(0_c), axis::integer<>(0, 2))); - BOOST_TEST(axis_equal(Type(), h2_01.axis(1_c), axis::integer<>(0, 3))); + BOOST_TEST(h2_01.axis(0_c) == axis::integer<>(0, 2)); + BOOST_TEST(h2_01.axis(1_c) == axis::integer<>(0, 3)); auto h2_02 = h2.reduce_to(0_c, 2_c); BOOST_TEST_EQ(h2_02.dim(), 2); @@ -692,8 +682,8 @@ template void run_tests() { BOOST_TEST_EQ(h2_02.at(0, 1), 1); BOOST_TEST_EQ(h2_02.at(0, 2), 1); BOOST_TEST_EQ(h2_02.at(1, 2), 1); - BOOST_TEST(axis_equal(Type(), h2_02.axis(0_c), axis::integer<>(0, 2))); - BOOST_TEST(axis_equal(Type(), h2_02.axis(1_c), axis::integer<>(0, 4))); + BOOST_TEST(h2_02.axis(0_c) == axis::integer<>(0, 2)); + BOOST_TEST(h2_02.axis(1_c) == axis::integer<>(0, 4)); auto h2_12 = h2.reduce_to(1_c, 2_c); BOOST_TEST_EQ(h2_12.dim(), 2); @@ -702,8 +692,8 @@ template void run_tests() { BOOST_TEST_EQ(h2_12.at(1, 0), 1); BOOST_TEST_EQ(h2_12.at(1, 1), 1); BOOST_TEST_EQ(h2_12.at(0, 2), 2); - BOOST_TEST(axis_equal(Type(), h2_12.axis(0_c), axis::integer<>(0, 3))); - BOOST_TEST(axis_equal(Type(), h2_12.axis(1_c), axis::integer<>(0, 4))); + BOOST_TEST(h2_12.axis(0_c) == axis::integer<>(0, 3)); + BOOST_TEST(h2_12.axis(1_c) == axis::integer<>(0, 4)); } // custom axis @@ -726,7 +716,7 @@ template void run_tests() { h("9"); BOOST_TEST_EQ(h.dim(), 1); - BOOST_TEST(h.axis() == custom_axis(0, 3)); + BOOST_TEST_EQ(h.axis(), custom_axis(0, 3)); BOOST_TEST_EQ(h.at(0), 1); BOOST_TEST_EQ(h.at(1), 1); BOOST_TEST_EQ(h.at(2), 0); @@ -980,7 +970,7 @@ int main() { BOOST_TEST_EQ(sum(h1_0), 5); BOOST_TEST_EQ(h1_0.at(0), 2); BOOST_TEST_EQ(h1_0.at(1), 3); - BOOST_TEST(axis_equal(dynamic_tag(), h1_0.axis(), h1.axis(0_c))); + BOOST_TEST(h1_0.axis() == h1.axis(0_c)); auto h1_1 = h1.reduce_to(1); BOOST_TEST_EQ(h1_1.dim(), 1); @@ -988,7 +978,7 @@ int main() { BOOST_TEST_EQ(h1_1.at(0), 2); BOOST_TEST_EQ(h1_1.at(1), 2); BOOST_TEST_EQ(h1_1.at(2), 1); - BOOST_TEST(axis_equal(dynamic_tag(), h1_1.axis(), h1.axis(1_c))); + BOOST_TEST(h1_1.axis() == h1.axis(1_c)); } // histogram iterator diff --git a/test/speed_cpp.cpp b/test/speed_cpp.cpp index dd2b627c..894988f9 100644 --- a/test/speed_cpp.cpp +++ b/test/speed_cpp.cpp @@ -137,11 +137,11 @@ int main() { compare_1d>, adaptive_storage>>(nfill, itype)); printf("hd_ss %.3f\n", - compare_1d>>( nfill, itype)); printf("hd_sd %.3f\n", - compare_1d>( + compare_1d>( nfill, itype)); } @@ -160,11 +160,11 @@ int main() { mpl::vector, axis::regular<>>, adaptive_storage>>(nfill, itype)); printf("hd_ss %.3f\n", - compare_2d>>( nfill, itype)); printf("hd_sd %.3f\n", - compare_2d>( + compare_2d>( nfill, itype)); } @@ -183,11 +183,11 @@ int main() { mpl::vector, axis::regular<>, axis::regular<>>, adaptive_storage>>(nfill, itype)); printf("hd_ss %.3f\n", - compare_3d>>( nfill, itype)); printf("hd_sd %.3f\n", - compare_3d>( + compare_3d>( nfill, itype)); } @@ -208,11 +208,11 @@ int main() { axis::regular<>, axis::regular<>, axis::regular<>>, adaptive_storage>>(nfill, itype)); printf("hd_ss %.3f\n", - compare_6d>>( nfill, itype)); printf("hd_sd %.3f\n", - compare_6d>( + compare_6d>( nfill, itype)); } }