summaryrefslogtreecommitdiffstats
path: root/src/boost/libs/safe_numerics/test/test_multiply_native.cpp
blob: 4c4a48ed853ffbe4889f10c1c86f94f420226610 (plain)
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
//  Copyright (c) 2012 Robert Ramey
//
// Distributed under 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)

#include <iostream>

#include <boost/safe_numerics/safe_integer.hpp>
#include "test_multiply_native_results.hpp"

template <class T>
using safe_t = boost::safe_numerics::safe<
    T,
    boost::safe_numerics::native
>;
#include "test_multiply.hpp"

#include <boost/mp11/list.hpp>
#include <boost/mp11/algorithm.hpp>
#include <boost/core/demangle.hpp>

using namespace boost::mp11;

template<typename L>
struct test {
    static_assert(mp_is_list<L>(), "must be a list of integral constants");
    bool m_error;
    test(bool b = true) : m_error(b) {}
    operator bool(){
        return m_error;
    }
    template<typename T>
    void operator()(const T &){
        static_assert(mp_is_list<T>(), "must be a list of two integral constants");
        constexpr size_t i1 = mp_first<T>(); // index of first argument
        constexpr size_t i2 = mp_second<T>();// index of second argument
        std::cout << i1 << ',' << i2 << ',';
        using T1 = typename mp_at_c<L, i1>::value_type;
        using T2 = typename mp_at_c<L, i2>::value_type;
        m_error &= test_multiply<T1, T2>(
            mp_at_c<L, i1>()(), // value of first argument
            mp_at_c<L, i2>()(), // value of second argument
            boost::core::demangle(typeid(T1).name()).c_str(),
            boost::core::demangle(typeid(T2).name()).c_str(),
            test_multiplication_native_result[i1][i2]
        );
    }
};

#include "check_symmetry.hpp"

int main(){
    static_assert(
        check_symmetry(test_multiplication_native_result),
        "sanity check on test matrix - should be symmetrical"
    );

    test<test_values> rval(true);

    using value_indices = mp_iota_c<mp_size<test_values>::value>;
    mp_for_each<
        mp_product<mp_list, value_indices, value_indices>
    >(rval);

    std::cout << (rval ? "success!" : "failure") << std::endl;
    return ! rval ;
}