diffmax_t.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. // Range v3 library
  2. //
  3. // Copyright Eric Niebler 2019-present
  4. //
  5. // Use, modification and distribution is subject to the
  6. // Boost Software License, Version 1.0. (See accompanying
  7. // file LICENSE_1_0.txt or copy at
  8. // http://www.boost.org/LICENSE_1_0.txt)
  9. //
  10. // Project home: https://github.com/ericniebler/range-v3
  11. #include <range/v3/iterator/diffmax_t.hpp>
  12. #include "../simple_test.hpp"
  13. #include "../test_utils.hpp"
  14. #include <iomanip>
  15. #include <functional>
  16. using ranges::detail::diffmax_t;
  17. template<template<typename> class Op>
  18. void check_1(std::ptrdiff_t a, std::ptrdiff_t b)
  19. {
  20. // std::cout << std::dec;
  21. // std::cout << a << "&" << b << " == " << (a&b) << std::endl;
  22. // std::cout << std::hex;
  23. // std::cout << a << "&" << b << " == " << (a&b) << std::endl;
  24. CHECK(Op<diffmax_t>{}(a, b) == Op<std::ptrdiff_t>{}(a, b));
  25. }
  26. template<>
  27. void check_1<std::divides>(std::ptrdiff_t a, std::ptrdiff_t b)
  28. {
  29. if(b)
  30. CHECK(std::divides<diffmax_t>{}(a, b) == std::divides<std::ptrdiff_t>{}(a, b));
  31. }
  32. template<>
  33. void check_1<std::modulus>(std::ptrdiff_t a, std::ptrdiff_t b)
  34. {
  35. if(b)
  36. CHECK(std::modulus<diffmax_t>{}(a, b) == std::modulus<std::ptrdiff_t>{}(a, b));
  37. }
  38. template<template<typename> class Op>
  39. void check()
  40. {
  41. check_1<Op>(0, 0);
  42. check_1<Op>(-1, 0);
  43. check_1<Op>(0, -1);
  44. check_1<Op>(1, 0);
  45. check_1<Op>(0, 1);
  46. check_1<Op>(1, 1);
  47. check_1<Op>(-1, -1);
  48. check_1<Op>(-5, -4);
  49. check_1<Op>(-4, -5);
  50. check_1<Op>(5, -4);
  51. check_1<Op>(-4, 5);
  52. check_1<Op>(-5, 4);
  53. check_1<Op>(4, -5);
  54. }
  55. int main()
  56. {
  57. check<std::plus>();
  58. check<std::minus>();
  59. check<std::multiplies>();
  60. check<std::divides>();
  61. check<std::modulus>();
  62. check<std::bit_and>();
  63. check<std::bit_or>();
  64. check<std::bit_xor>();
  65. return test_result();
  66. }