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