// 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 #include // test conversion to T2 from different literal types template constexpr bool test_cast_constexpr( const T1 & v1, char result ){ const boost::safe_numerics::checked_result r2 = boost::safe_numerics::checked::cast(v1); return ('x' == result) ? r2.exception() : ! r2.exception(); } #include "test_checked_cast.hpp" #include // mp_iota #include // mp_first, mp_second, mp_size, mp_is_list using namespace boost::mp11; // given a list of integral constants I, return a list of values template struct get_values { static_assert(mp_is_list(), "must be a list of two types"); static_assert(2 == mp_size::value, "must be a list of two types"); static constexpr const size_t first = mp_first(); // index of first argument static constexpr const size_t second = mp_second();// index of second argument }; template struct test_pair_constexpr { using pair = get_values; using TResult = mp_at>; using TArg = typename mp_at>::value_type; static constexpr TArg v = mp_at>()(); static constexpr bool value = test_cast_constexpr( v, test_result_cast[pair::first][pair::second] ); }; int main(){ // list of indices for values (integral constants) using value_indices = mp_iota_c::value>; // list of indices for types (integral constants) using type_indices = mp_iota_c::value>; // all combinations of type index, value index using index_pairs = mp_product; // test all type/value pairs to verify that cast can be done. static_assert( mp_all_of::value, "all type/value pairs correctly cast" ); return 0; }