1 // Copyright (c) 2012 Robert Ramey
2 //
3 // Distributed under the Boost Software License, Version 1.0. (See
4 // accompanying file LICENSE_1_0.txt or copy at
5 // http://www.boost.org/LICENSE_1_0.txt)
6
7 #include <iostream>
8
9 #include <boost/safe_numerics/safe_integer.hpp>
10 #include <boost/safe_numerics/automatic.hpp>
11 #include "test_add_automatic_results.hpp"
12
13 template <class T>
14 using safe_t = boost::safe_numerics::safe<
15 T,
16 boost::safe_numerics::automatic
17 >;
18
19 #include "test_add.hpp"
20
21 #include <boost/mp11/list.hpp>
22 #include <boost/mp11/algorithm.hpp>
23 #include <boost/core/demangle.hpp>
24
25 using namespace boost::mp11;
26
27 template<typename L>
28 struct test {
29 static_assert(mp_is_list<L>(), "must be a list of integral constants");
30 bool m_error;
testtest31 test(bool b = true) : m_error(b) {}
operator booltest32 operator bool(){
33 return m_error;
34 }
35 template<typename T>
operator ()test36 void operator()(const T &){
37 static_assert(mp_is_list<T>(), "must be a list of two integral constants");
38 constexpr size_t i1 = mp_first<T>(); // index of first argument
39 constexpr size_t i2 = mp_second<T>();// index of second argument
40 std::cout << i1 << ',' << i2 << ',';
41 using T1 = typename mp_at_c<L, i1>::value_type;
42 using T2 = typename mp_at_c<L, i2>::value_type;
43 m_error &= test_add(
44 mp_at_c<L, i1>()(), // value of first argument
45 mp_at_c<L, i2>()(), // value of second argument
46 boost::core::demangle(typeid(T1).name()).c_str(),
47 boost::core::demangle(typeid(T2).name()).c_str(),
48 test_addition_automatic_result[i1][i2]
49 );
50 }
51 };
52
53 #include "check_symmetry.hpp"
54
main()55 int main(){
56 static_assert(
57 check_symmetry(test_addition_automatic_result),
58 "sanity check on test matrix - should be symmetrical"
59 );
60
61 //TEST_EACH_VALUE_PAIR
62 test<test_values> rval(true);
63
64 using value_indices = mp_iota_c<mp_size<test_values>::value>;
65 mp_for_each<
66 mp_product<mp_list, value_indices, value_indices>
67 >(rval);
68
69 std::cout << (rval ? "success!" : "failure") << std::endl;
70 return ! rval ;
71 }
72