Imported Upstream version 1.72.0
[platform/upstream/boost.git] / libs / histogram / test / deduction_guides_test.cpp
index 8e6ad54..2bd0f8b 100644 (file)
@@ -9,7 +9,6 @@
 #include <boost/histogram/accumulators/weighted_sum.hpp>
 #include <boost/histogram/axis.hpp>
 #include <boost/histogram/axis/ostream.hpp>
-#include "throw_exception.hpp"
 #include <boost/histogram/histogram.hpp>
 #include <boost/histogram/ostream.hpp>
 #include <boost/histogram/storage_adaptor.hpp>
 #include <type_traits>
 #include <vector>
 #include "std_ostream.hpp"
+#include "throw_exception.hpp"
 
 using namespace boost::histogram;
 namespace tr = axis::transform;
 
 // tests requires a C++17 compatible compiler
 
+#define TEST BOOST_TEST_TRAIT_SAME
+
 int main() {
+  using axis::null_type;
+
+  {
+    using axis::regular;
+    BOOST_TEST_TRAIT_SAME(decltype(regular(1, 0.0, 1.0)),
+                          regular<double, tr::id, null_type>);
+    BOOST_TEST_TRAIT_SAME(decltype(regular(1, 0, 1)), regular<double, tr::id, null_type>);
+    BOOST_TEST_TRAIT_SAME(decltype(regular(1, 0.0f, 1.0f)),
+                          regular<float, tr::id, null_type>);
+    BOOST_TEST_TRAIT_SAME(decltype(regular(1, 0, 1, 0)), regular<double, tr::id, int>);
+    BOOST_TEST_TRAIT_SAME(decltype(regular(1, 0.0f, 1.0f, "x")),
+                          regular<float, tr::id, std::string>);
+    BOOST_TEST_TRAIT_SAME(decltype(regular(tr::sqrt(), 1, 0, 1)),
+                          regular<double, tr::sqrt, null_type>);
+    BOOST_TEST_TRAIT_SAME(decltype(regular(tr::sqrt(), 1, 0.0f, 1.0f, "x")),
+                          regular<float, tr::sqrt, std::string>);
+    BOOST_TEST_TRAIT_SAME(decltype(regular(tr::sqrt(), 1, 0, 1, 0)),
+                          regular<double, tr::sqrt, int>);
+  }
+
+  {
+    using axis::integer;
+    BOOST_TEST_TRAIT_SAME(decltype(integer(1, 2)), integer<int, null_type>);
+    BOOST_TEST_TRAIT_SAME(decltype(integer(1l, 2l)), integer<int, null_type>);
+    BOOST_TEST_TRAIT_SAME(decltype(integer(1.0, 2.0)), integer<double, null_type>);
+    BOOST_TEST_TRAIT_SAME(decltype(integer(1.0f, 2.0f)), integer<float, null_type>);
+    BOOST_TEST_TRAIT_SAME(decltype(integer(1, 2, "foo")), integer<int, std::string>);
+    BOOST_TEST_TRAIT_SAME(decltype(integer(1, 2, 0)), integer<int, int>);
+  }
+
+  {
+    using axis::variable;
+    BOOST_TEST_TRAIT_SAME(decltype(variable{-1.0f, 1.0f}), variable<float, null_type>);
+    BOOST_TEST_TRAIT_SAME(decltype(variable{-1, 0, 1, 2}), variable<double, null_type>);
+    BOOST_TEST_TRAIT_SAME(decltype(variable{-1.0, 1.0}), variable<double, null_type>);
+    BOOST_TEST_TRAIT_SAME(decltype(variable({-1, 0, 1}, "foo")),
+                          variable<double, std::string>);
+    BOOST_TEST_TRAIT_SAME(decltype(variable({-1, 1}, 0)), variable<double, int>);
+
+    BOOST_TEST_TRAIT_SAME(decltype(variable(std::vector<int>{{-1, 1}})),
+                          variable<double, null_type>);
+    BOOST_TEST_TRAIT_SAME(decltype(variable(std::vector<float>{{-1.0f, 1.0f}})),
+                          variable<float, null_type>);
+    BOOST_TEST_TRAIT_SAME(decltype(variable(std::vector<int>{{-1, 1}}, "foo")),
+                          variable<double, std::string>);
+    BOOST_TEST_TRAIT_SAME(decltype(variable(std::vector<int>{{-1, 1}}, 0)),
+                          variable<double, int>);
+  }
+
   {
-    axis::regular a(1, 0.0, 1.0);
-    axis::regular b(1, 0, 1);
-    axis::regular c(1, 0.0f, 1.0f);
-    axis::regular d(1, 0, 1, "foo");
-    axis::regular e(1, 0, 1, axis::null_type{});
-    axis::regular f(tr::sqrt(), 1, 0, 1);
-    axis::regular g(tr::sqrt(), 1, 0, 1, "foo");
-    axis::regular h(tr::sqrt(), 1, 0, 1, axis::null_type{});
-
-    BOOST_TEST_TRAIT_SAME(decltype(a), axis::regular<>);
-    BOOST_TEST_TRAIT_SAME(decltype(b), axis::regular<>);
-    BOOST_TEST_TRAIT_SAME(decltype(c), axis::regular<float>);
-    BOOST_TEST_TRAIT_SAME(decltype(d), axis::regular<>);
-    BOOST_TEST_TRAIT_SAME(decltype(e), axis::regular<double, tr::id, axis::null_type>);
-    BOOST_TEST_TRAIT_SAME(decltype(f), axis::regular<double, tr::sqrt>);
-    BOOST_TEST_TRAIT_SAME(decltype(g), axis::regular<double, tr::sqrt>);
-    BOOST_TEST_TRAIT_SAME(decltype(h), axis::regular<double, tr::sqrt, axis::null_type>);
+    using axis::category;
+    BOOST_TEST_TRAIT_SAME(decltype(category{1, 2}), category<int, null_type>);
+    BOOST_TEST_TRAIT_SAME(decltype(category{"x", "y"}), category<std::string, null_type>);
+    BOOST_TEST_TRAIT_SAME(decltype(category({1, 2}, "foo")), category<int, std::string>);
+    BOOST_TEST_TRAIT_SAME(decltype(category({1, 2}, 0)), category<int, int>);
   }
 
   {
-    axis::integer a(1, 2);
-    axis::integer b(1l, 2l);
-    axis::integer c(1.0, 2.0);
-    axis::integer d(1.0f, 2.0f);
-    axis::integer e(1, 2, "foo");
-    axis::integer f(1, 2, axis::null_type{});
-
-    BOOST_TEST_TRAIT_SAME(decltype(a), axis::integer<int>);
-    BOOST_TEST_TRAIT_SAME(decltype(b), axis::integer<int>);
-    BOOST_TEST_TRAIT_SAME(decltype(c), axis::integer<double>);
-    BOOST_TEST_TRAIT_SAME(decltype(d), axis::integer<float>);
-    BOOST_TEST_TRAIT_SAME(decltype(e), axis::integer<int>);
-    BOOST_TEST_TRAIT_SAME(decltype(f), axis::integer<int, axis::null_type>);
+    auto h = histogram(axis::regular(3, -1, 1), axis::integer(0, 4));
+    BOOST_TEST_TRAIT_SAME(decltype(h),
+                          histogram<std::tuple<axis::regular<double, tr::id, null_type>,
+                                               axis::integer<int, null_type>>>);
+    BOOST_TEST_EQ(h.axis(0), axis::regular(3, -1, 1));
+    BOOST_TEST_EQ(h.axis(1), axis::integer(0, 4));
   }
 
   {
-    axis::variable a{-1, 1};
-    axis::variable b{-1.f, 1.f};
-    axis::variable c{-1.0, 1.0};
-    axis::variable d({-1, 1}, "foo");
-    axis::variable e({-1, 1}, axis::null_type{});
-
-    std::vector<int> vi{{-1, 1}};
-    std::vector<float> vf{{-1.f, 1.f}};
-    axis::variable f(vi);
-    axis::variable g(vf);
-    axis::variable h(vi, "foo");
-    axis::variable i(vi, axis::null_type{});
-
-    BOOST_TEST_TRAIT_SAME(decltype(a), axis::variable<>);
-    BOOST_TEST_TRAIT_SAME(decltype(b), axis::variable<float>);
-    BOOST_TEST_TRAIT_SAME(decltype(c), axis::variable<>);
-    BOOST_TEST_TRAIT_SAME(decltype(d), axis::variable<>);
-    BOOST_TEST_TRAIT_SAME(decltype(e), axis::variable<double, axis::null_type>);
-    BOOST_TEST_TRAIT_SAME(decltype(f), axis::variable<>);
-    BOOST_TEST_TRAIT_SAME(decltype(g), axis::variable<float>);
-    BOOST_TEST_TRAIT_SAME(decltype(h), axis::variable<>);
-    BOOST_TEST_TRAIT_SAME(decltype(i), axis::variable<double, axis::null_type>);
+    auto h = histogram(std::tuple(axis::regular(3, -1, 1), axis::integer(0, 4)),
+                       weight_storage());
+    BOOST_TEST_TRAIT_SAME(decltype(h),
+                          histogram<std::tuple<axis::regular<double, tr::id, null_type>,
+                                               axis::integer<int, null_type>>,
+                                    weight_storage>);
+    BOOST_TEST_EQ(h.axis(0), axis::regular(3, -1, 1));
+    BOOST_TEST_EQ(h.axis(1), axis::integer(0, 4));
   }
 
   {
-    axis::category a{1, 2};
-    axis::category b{"x", "y"};
-    axis::category c({1, 2}, "foo");
-    axis::category d({1, 2}, axis::null_type{});
-
-    BOOST_TEST_TRAIT_SAME(decltype(a), axis::category<int>);
-    BOOST_TEST_TRAIT_SAME(decltype(b), axis::category<std::string>);
-    BOOST_TEST_TRAIT_SAME(decltype(c), axis::category<int>);
-    BOOST_TEST_TRAIT_SAME(decltype(d), axis::category<int, axis::null_type>);
+    auto a0 = axis::regular(5, 0, 5);
+    auto a1 = axis::regular(3, -1, 1);
+    auto axes = {a0, a1};
+    auto h = histogram(axes);
+    BOOST_TEST_TRAIT_SAME(
+        decltype(h), histogram<std::vector<axis::regular<double, tr::id, null_type>>>);
+    BOOST_TEST_EQ(h.rank(), 2);
+    BOOST_TEST_EQ(h.axis(0), a0);
+    BOOST_TEST_EQ(h.axis(1), a1);
   }
 
   {
-    auto a0 = axis::regular(3, -1, 1, axis::null_type{});
-    auto a1 = axis::integer(0, 4, axis::null_type{});
-    auto a = histogram(std::make_tuple(a0, a1));
-    BOOST_TEST_EQ(a.rank(), 2);
-    BOOST_TEST_EQ(a.axis(0), a0);
-    BOOST_TEST_EQ(a.axis(1), a1);
-
-    auto a2 = axis::regular(5, 0, 5, axis::null_type{});
-    // don't use deduction guides for vector, support depends on stdc++ version
-    std::vector<decltype(a0)> axes{{a0, a2}};
-    auto b = histogram(axes, weight_storage());
-    BOOST_TEST_EQ(b.rank(), 2);
-    BOOST_TEST_EQ(b.axis(0), a0);
-    BOOST_TEST_EQ(b.axis(1), a2);
+    auto a0 = axis::regular(5, 0, 5);
+    auto a1 = axis::regular(3, -1, 1);
+    auto axes = {a0, a1};
+    auto h = histogram(axes, weight_storage());
+    BOOST_TEST_TRAIT_SAME(
+        decltype(h),
+        histogram<std::vector<axis::regular<double, tr::id, null_type>>, weight_storage>);
+    BOOST_TEST_EQ(h.rank(), 2);
+    BOOST_TEST_EQ(h.axis(0), a0);
+    BOOST_TEST_EQ(h.axis(1), a1);
   }
+
+  {
+    auto a0 = axis::regular(5, 0, 5);
+    auto a1 = axis::regular(3, -1, 1);
+    auto axes = std::vector<decltype(a0)>{{a0, a1}};
+    auto h = histogram(axes);
+    BOOST_TEST_TRAIT_SAME(
+        decltype(h), histogram<std::vector<axis::regular<double, tr::id, null_type>>>);
+    BOOST_TEST_EQ(h.rank(), 2);
+    BOOST_TEST_EQ(h.axis(0), a0);
+    BOOST_TEST_EQ(h.axis(1), a1);
+  }
+
   return boost::report_errors();
 }