Imported Upstream version 1.72.0
[platform/upstream/boost.git] / libs / histogram / test / detail_accumulator_traits_test.cpp
1 // Copyright 2019 Hans Dembinski
2 //
3 // Distributed under the Boost Software License, Version 1.0.
4 // (See accompanying file LICENSE_1_0.txt
5 // or copy at http://www.boost.org/LICENSE_1_0.txt)
6
7 #include <boost/core/lightweight_test.hpp>
8 #include <boost/core/lightweight_test_trait.hpp>
9 #include <boost/histogram/detail/accumulator_traits.hpp>
10 #include <boost/histogram/weight.hpp>
11 #include <tuple>
12
13 namespace dtl = boost::histogram::detail;
14
15 int main() {
16   using boost::histogram::weight_type;
17
18   struct A1 {
19     void operator()(){};
20   };
21
22   BOOST_TEST_NOT(dtl::accumulator_traits<A1>::wsupport::value);
23   BOOST_TEST_TRAIT_SAME(typename dtl::accumulator_traits<A1>::args, std::tuple<>);
24
25   struct A2 {
26     void operator()(int, double) {}
27   };
28
29   BOOST_TEST_NOT(dtl::accumulator_traits<A2>::wsupport::value);
30   BOOST_TEST_TRAIT_SAME(typename dtl::accumulator_traits<A2>::args,
31                         std::tuple<int, double>);
32
33   struct A3 {
34     void operator()() {}
35     void operator()(weight_type<int>) {}
36   };
37
38   BOOST_TEST(dtl::accumulator_traits<A3>::wsupport::value);
39   BOOST_TEST_TRAIT_SAME(typename dtl::accumulator_traits<A3>::args, std::tuple<>);
40
41   struct A4 {
42     void operator()(int, double, char) {}
43     void operator()(weight_type<int>, int, double, char) {}
44   };
45
46   BOOST_TEST(dtl::accumulator_traits<A4>::wsupport::value);
47   BOOST_TEST_TRAIT_SAME(typename dtl::accumulator_traits<A4>::args,
48                         std::tuple<int, double, char>);
49
50   struct A5 {
51     void operator()(const weight_type<int>, int) {}
52   };
53
54   BOOST_TEST(dtl::accumulator_traits<A5>::wsupport::value);
55   BOOST_TEST_TRAIT_SAME(typename dtl::accumulator_traits<A5>::args, std::tuple<int>);
56
57   struct A6 {
58     void operator()(const weight_type<int>&, const int) {}
59   };
60
61   BOOST_TEST(dtl::accumulator_traits<A6>::wsupport::value);
62   BOOST_TEST_TRAIT_SAME(typename dtl::accumulator_traits<A6>::args, std::tuple<int>);
63
64   struct A7 {
65     void operator()(weight_type<int>&&, int&&) {}
66   };
67
68   BOOST_TEST(dtl::accumulator_traits<A7>::wsupport::value);
69   BOOST_TEST_TRAIT_SAME(typename dtl::accumulator_traits<A7>::args, std::tuple<int&&>);
70
71   struct B {
72     int operator+=(int) { return 0; }
73   };
74
75   BOOST_TEST(dtl::accumulator_traits<B>::wsupport::value);
76   BOOST_TEST_TRAIT_SAME(typename dtl::accumulator_traits<B>::args, std::tuple<>);
77
78   BOOST_TEST(dtl::accumulator_traits<int>::wsupport::value);
79   BOOST_TEST_TRAIT_SAME(dtl::accumulator_traits<int>::args, std::tuple<>);
80
81   return boost::report_errors();
82 }