File: diffmax_t.cpp

package info (click to toggle)
range-v3 0.12.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,652 kB
  • sloc: cpp: 76,839; xml: 226; sh: 89; python: 34; makefile: 19; perl: 15
file content (72 lines) | stat: -rw-r--r-- 1,823 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// Range v3 library
//
//  Copyright Eric Niebler 2019-present
//
//  Use, modification and distribution is subject to 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)
//
// Project home: https://github.com/ericniebler/range-v3

#include <range/v3/iterator/diffmax_t.hpp>
#include "../simple_test.hpp"
#include "../test_utils.hpp"

#include <iomanip>
#include <functional>
using ranges::detail::diffmax_t;

template<template<typename> class Op>
void check_1(std::ptrdiff_t a, std::ptrdiff_t b)
{
    // std::cout << std::dec;
    // std::cout << a << "&" << b << " == " << (a&b) << std::endl;
    // std::cout << std::hex;
    // std::cout << a << "&" << b << " == " << (a&b) << std::endl;
    CHECK(Op<diffmax_t>{}(a, b) == Op<std::ptrdiff_t>{}(a, b));
}
template<>
void check_1<std::divides>(std::ptrdiff_t a, std::ptrdiff_t b)
{
    if(b)
        CHECK(std::divides<diffmax_t>{}(a, b) == std::divides<std::ptrdiff_t>{}(a, b));
}
template<>
void check_1<std::modulus>(std::ptrdiff_t a, std::ptrdiff_t b)
{
    if(b)
        CHECK(std::modulus<diffmax_t>{}(a, b) == std::modulus<std::ptrdiff_t>{}(a, b));
}

template<template<typename> class Op>
void check()
{
    check_1<Op>(0, 0);
    check_1<Op>(-1, 0);
    check_1<Op>(0, -1);
    check_1<Op>(1, 0);
    check_1<Op>(0, 1);
    check_1<Op>(1, 1);
    check_1<Op>(-1, -1);
    check_1<Op>(-5, -4);
    check_1<Op>(-4, -5);
    check_1<Op>(5, -4);
    check_1<Op>(-4, 5);
    check_1<Op>(-5, 4);
    check_1<Op>(4, -5);
}

int main()
{
    check<std::plus>();
    check<std::minus>();
    check<std::multiplies>();
    check<std::divides>();
    check<std::modulus>();
    check<std::bit_and>();
    check<std::bit_or>();
    check<std::bit_xor>();

    return test_result();
}