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_subtract_native_results.hpp"
12 
13 template <class T>
14 using safe_t = boost::safe_numerics::safe<
15     T,
16     boost::safe_numerics::native
17 >;
18 #include "test_subtract.hpp"
19 
20 using namespace boost::mp11;
21 
22 #include <boost/mp11/list.hpp>
23 #include <boost/mp11/algorithm.hpp>
24 #include <boost/core/demangle.hpp>
25 
26 using namespace boost::mp11;
27 
28 template<typename L>
29 struct test {
30     static_assert(mp_is_list<L>(), "must be a list of integral constants");
31     bool m_error;
testtest32     test(bool b = true) : m_error(b) {}
operator booltest33     operator bool(){
34         return m_error;
35     }
36     template<typename T>
operator ()test37     void operator()(const T &){
38         static_assert(mp_is_list<T>(), "must be a list of two integral constants");
39         constexpr size_t i1 = mp_first<T>(); // index of first argument
40         constexpr size_t i2 = mp_second<T>();// index of second argument
41         std::cout << i1 << ',' << i2 << ',';
42         using T1 = typename mp_at_c<L, i1>::value_type;
43         using T2 = typename mp_at_c<L, i2>::value_type;
44         m_error &= test_subtract(
45             boost::mp11::mp_at_c<L, i1>()(), // value of first argument
46             boost::mp11::mp_at_c<L, i2>()(), // value of second argument
47             boost::core::demangle(typeid(T1).name()).c_str(),
48             boost::core::demangle(typeid(T2).name()).c_str(),
49             test_subtraction_native_result[i1][i2]
50         );
51     }
52 };
53 
main()54 int main(){
55     //TEST_EACH_VALUE_PAIR
56     test<test_values> rval(true);
57 
58     using value_indices = mp_iota_c<mp_size<test_values>::value>;
59     mp_for_each<
60         mp_product<mp_list, value_indices, value_indices>
61     >(rval);
62 
63     std::cout << (rval ? "success!" : "failure") << std::endl;
64     return ! rval ;
65 }
66