• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef BOOST_TEST_LESS_THAN_CONSTEXPR_HPP
2 #define BOOST_TEST_LESS_THAN_CONSTEXPR_HPP
3 
4 //  Copyright (c) 2019 Robert Ramey
5 //
6 // Distributed under the Boost Software License, Version 1.0. (See
7 // accompanying file LICENSE_1_0.txt or copy at
8 // http://www.boost.org/LICENSE_1_0.txt)
9 
10 #include <boost/config.hpp> // BOOST_CLANG
11 #include <boost/safe_numerics/safe_integer.hpp>
12 
13 #if BOOST_CLANG==1
14 #pragma GCC diagnostic push
15 #pragma GCC diagnostic ignored "-Wunused-comparison"
16 #endif
17 
18 template<class T1, class T2>
test_less_than_constexpr(T1 v1,T2 v2,char expected_result)19 constexpr bool test_less_than_constexpr(
20     T1 v1,
21     T2 v2,
22     char expected_result
23 ){
24     using namespace boost::safe_numerics;
25     // if we don't expect the operation to pass, we can't
26     // check the constexpr version of the calculation so
27     // just return success.
28     if(expected_result == 'x')
29         return true;
30     safe_t<T1>(v1) < v2;
31     v1 < safe_t<T2>(v2);
32     safe_t<T1>(v1) < safe_t<T2>(v2);
33     return true; // correct result
34 }
35 
36 #if BOOST_CLANG==1
37 #pragma GCC diagnostic pop
38 #endif
39 
40 #endif // BOOST_TEST_LESS_THAN_CONSTEXPR_HPP
41