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