detail_accumulator_traits_test.cpp 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. #include <boost/core/lightweight_test.hpp>
  7. #include <boost/core/lightweight_test_trait.hpp>
  8. #include <boost/histogram/detail/accumulator_traits.hpp>
  9. #include <boost/histogram/weight.hpp>
  10. #include <tuple>
  11. namespace dtl = boost::histogram::detail;
  12. int main() {
  13. using boost::histogram::weight_type;
  14. struct A1 {
  15. void operator()(){};
  16. };
  17. BOOST_TEST_NOT(dtl::accumulator_traits<A1>::wsupport::value);
  18. BOOST_TEST_TRAIT_SAME(typename dtl::accumulator_traits<A1>::args, std::tuple<>);
  19. struct A2 {
  20. void operator()(int, double) {}
  21. };
  22. BOOST_TEST_NOT(dtl::accumulator_traits<A2>::wsupport::value);
  23. BOOST_TEST_TRAIT_SAME(typename dtl::accumulator_traits<A2>::args,
  24. std::tuple<int, double>);
  25. struct A3 {
  26. void operator()() {}
  27. void operator()(weight_type<int>) {}
  28. };
  29. BOOST_TEST(dtl::accumulator_traits<A3>::wsupport::value);
  30. BOOST_TEST_TRAIT_SAME(typename dtl::accumulator_traits<A3>::args, std::tuple<>);
  31. struct A4 {
  32. void operator()(int, double, char) {}
  33. void operator()(weight_type<int>, int, double, char) {}
  34. };
  35. BOOST_TEST(dtl::accumulator_traits<A4>::wsupport::value);
  36. BOOST_TEST_TRAIT_SAME(typename dtl::accumulator_traits<A4>::args,
  37. std::tuple<int, double, char>);
  38. struct A5 {
  39. void operator()(const weight_type<int>, int) {}
  40. };
  41. BOOST_TEST(dtl::accumulator_traits<A5>::wsupport::value);
  42. BOOST_TEST_TRAIT_SAME(typename dtl::accumulator_traits<A5>::args, std::tuple<int>);
  43. struct A6 {
  44. void operator()(const weight_type<int>&, const int) {}
  45. };
  46. BOOST_TEST(dtl::accumulator_traits<A6>::wsupport::value);
  47. BOOST_TEST_TRAIT_SAME(typename dtl::accumulator_traits<A6>::args, std::tuple<int>);
  48. struct A7 {
  49. void operator()(weight_type<int>&&, int&&) {}
  50. };
  51. BOOST_TEST(dtl::accumulator_traits<A7>::wsupport::value);
  52. BOOST_TEST_TRAIT_SAME(typename dtl::accumulator_traits<A7>::args, std::tuple<int&&>);
  53. struct B {
  54. int operator+=(int) { return 0; }
  55. };
  56. BOOST_TEST(dtl::accumulator_traits<B>::wsupport::value);
  57. BOOST_TEST_TRAIT_SAME(typename dtl::accumulator_traits<B>::args, std::tuple<>);
  58. BOOST_TEST(dtl::accumulator_traits<int>::wsupport::value);
  59. BOOST_TEST_TRAIT_SAME(dtl::accumulator_traits<int>::args, std::tuple<>);
  60. return boost::report_errors();
  61. }